Skip to content

Commit

Permalink
add auto record example
Browse files Browse the repository at this point in the history
  • Loading branch information
GreatYYX committed Mar 22, 2019
1 parent c0ac123 commit d808505
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/basic/auto_record.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pandas as pd
import rltk

print('from dataframe...')

df = pd.read_csv('ds1.csv', encoding='latin-1')
df['id'] = df['doc_id'].astype('str')


class DFRecord(rltk.AutoGeneratedRecord):
pass


ds = rltk.Dataset(rltk.DataFrameReader(df), record_class=DFRecord)
for r in ds:
print(r.id, r.doc_id, r.doc_value)


print('set id column...')


@rltk.set_id('col1', function_=lambda x: str(x), keep_original=True)
class DFRecord2(rltk.AutoGeneratedRecord):
pass


df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
ds = rltk.Dataset(reader=rltk.DataFrameReader(df), record_class=DFRecord2)
for r in ds:
print(r.id, r.col1, r.col2)

0 comments on commit d808505

Please sign in to comment.