Skip to content

metravod/convert_df

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

ConvertDF

A small class that will help you make the pandas dataframe serialization process more controllable.

data = [[12, 'foo', 567.53], [45, 'bar', 421.3], [35, 'baz', 1321.5]]
cols = ['int_col', 'str_col', 'float_col']
df = pd.DataFrame(data, columns=cols)

ConvertDF(
    df.loc[:0], 
    rename_cols={'int_col': 'ids', 'str_col': 'type', 'float_col': 'value'}, 
    type_cols={'int_col': str, 'float_col': int},
    is_oneliner=True
).to_dict()

>>> {'ids': '12', 'type': 'foo', 'value': 567}

About

A small class that will help you make the pandas dataframe serialization process more controllable.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages