how to print dictionary data in the tabular form in python -
i have nested dictionary follows.i want print data in tabular form. condition here want print data in table example : birt, name, , sex. how can that?
import sys import pandas pd indi ={} indi = {'@i7@': {'birt': '15 nov 1925', 'fams': '@f2@', 'name': 'rose /campbell/', 'deat': '26 aug 2009', 'sex': 'f'}, '@i5@': {'birt': '15 sep 1928', 'fams': '@f3@', 'name': 'rosy /huleknberg/', 'deat': '10 mar 2010', 'sex': 'f'}} person = pd.dataframe(indi).t person.fillna(0, inplace=true) print(person)
output
birt deat famc fams name sex @i5@ 15 sep 1928 10 mar 2010 0 @f3@ rosy /huleknberg/ f @i7@ 15 nov 1925 26 aug 2009 0 @f2@ rose /campbell/ f
documentation: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.dataframe.filter.html
you can try use this:
print(person.filter(['birt', 'name', 'sex']))
output be:
birt name sex @i5@ 15 sep 1928 rosy /huleknberg/ f @i7@ 15 nov 1925 rose /campbell/ f
Comments
Post a Comment