Python 将字典附加到数据框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51774826/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:55:55 来源:igfitidea点击:
append dictionary to data frame
提问by cs0815
I have a function, which returns a dictionary like this:
我有一个函数,它返回一个这样的字典:
{'truth': 185.179993, 'day1': 197.22307753038834, 'day2': 197.26118010160317, 'day3': 197.19846975345905, 'day4': 197.1490578795196, 'day5': 197.37179265011116}
I am trying to append this dictionary to a dataframe like so:
我正在尝试将此字典附加到数据框,如下所示:
output = pd.DataFrame()
output.append(dictionary, ignore_index=True)
print(output.head())
Unfortunately, the printing of the dataframe results in an empty dataframe. Any ideas?
不幸的是,数据帧的打印会导致一个空的数据帧。有任何想法吗?
回答by alex
You don't assign the value to the result.
您没有将值分配给结果。
output = pd.DataFrame()
output = output.append(dictionary, ignore_index=True)
print(output.head())