[英]Creating a dictionary from DataFrame column and values
I have a DataFrame that looks like this:我有一个如下所示的 DataFrame:
A B C D
0 One Two Three Four
1 31 47 44 22
2 53 38 11 27
3 86 84 81 87
4 57 4 23 46
I want to create a loop that will give me key of one, two, three, with values of 53, 47, 44, 22 going down.我想创建一个循环,它会给我一、二、三的键,值是 53、47、44、22。 So first dict would be
所以第一个 dict 是
{'One': 31, 'Two': 47, 'Three': 44, 'Four' : 22}
next one下一个
{'One': 53, 'Two': 38, 'Three': 11, 'Four' : 22}
and so on.等等。
I have completly no clue how to accomplish it.我完全不知道如何实现它。 Any ideas?
有任何想法吗?
You can use DataFrame.to_dict() in order to accomplish it.您可以使用 DataFrame.to_dict() 来完成它。
You can find more about the topic on:您可以在以下位置找到有关该主题的更多信息:
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_dict.html https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_dict.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.