我正在尝试用字典附加一个熊猫数据框。但是,它没有附加。打印时我得到一个空的数据框。请告诉我代码中哪里出错了。
import pandas as pd
dfs = pd.DataFrame()
def tstfunc():
dicts = {'a': "pavan", 'b':"sunder"}
dfs.append(dicts, ignore_index=True)
print(dfs)
tstfunc()
答案 0 :(得分:0)
试试:
def tstfunc():
dfs = pd.DataFrame()
dicts = {'a': "pavan", 'b':"sunder"}
dfs=dfs.append(dicts, ignore_index=True)
return dfs
tstfunc()
调用 tstfunc()
时的输出:
a b
0 pavan sunder
或
dfs = pd.DataFrame()
def tstfunc():
dicts = {'a': "pavan", 'b':"sunder"}
return dfs.append(dicts, ignore_index=True)
tstfunc()
调用 tstfunc()
时的输出:
a b
0 pavan sunder