我正在尝试用字典附加一个熊猫数据框。但是,它没有附加。打印时我得到一个空的数据框。请告诉我在我的代码中哪里出错了。
import pandas as pd
dfs = pd.DataFrame()
def tstfunc():
dicts = {'a': "pavan", 'b':"sunder"}
dfs.append(dicts, ignore_index=True)
print(dfs)
tstfunc()
尝试:
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句