In [1]:
import pandas as pd
In [2]:
pd.__version__
Out[2]:
In [3]:
names = ['john','mary','peter','gary','anne']
ages = [33,22,45,23,12]
df = pd.DataFrame({
'names':names,
'ages':ages
})
df
Out[3]:
In [4]:
data_dicts = [
{'name':"john","gender":'male','age':45},
{'name':"mary", 'gender':"female",'age':19},
{'name':"peter",'gender':'male', 'age':34}
]
# must reassign since the append method does not work in place
df = pd.DataFrame.from_records(data_dicts)
df
Out[4]:
In [ ]:
In [5]:
df = pd.DataFrame()
# must reassign since the append method does not work in place
df = df.append({'col_a':5,'col_b':10}, ignore_index=True)
df = df.append({'col_a':1,'col_b':100}, ignore_index=True)
df = df.append({'col_a':32,'col_b':999}, ignore_index=True)
df
Out[5]:
In [6]:
data_dicts = [
{'name':"john","gender":'male','age':45},
{'name':"mary", 'gender':"female",'age':19},
{'name':"peter",'gender':'male', 'age':34}
]
# must reassign since the append method does not work in place
df = pd.DataFrame.from_records(data_dicts,)
df
Out[6]: