【发布时间】:2015-06-25 19:40:16
【问题描述】:
我有一个从 JSON 转换而来的 pandas DataFrame,并提取了我想要的列和行(很好地导出到 CSV)。
但是,我想进入几个“行中的级别”。我想使用类似的东西来迭代我的索引数据的选择:
df.likes[0]['count']
我的 DataFrame 被称为 df 和 likes 是列。我想访问整行的“count”值,将其打印回 DataFrame 的相同位置和列。
这是数据:
>>> df_likes.ix[0:94]
0 {u'count': 1685, u'anchorStr': u'1225924030067...
1 {u'count': 1944, u'anchorStr': u'1225924022404...
2 {u'count': 2586, u'anchorStr': u'1225924194077...
3 {u'count': 3075, u'anchorStr': u'1225924298746...
4 {u'count': 3263, u'anchorStr': u'1225924358464...
5 {u'count': 3390, u'anchorStr': u'1225924289589...
6 {u'count': 4306, u'anchorStr': u'1225924191359...
7 {u'count': 751, u'anchorStr': u'12259244210391...
8 {u'count': 2425, u'anchorStr': u'1225924419831...
9 {u'count': 2628, u'anchorStr': u'1225924362763...
10 {u'count': 1521, u'anchorStr': u'1225924213802...
【问题讨论】:
-
“将其打印回相同的位置和列”到底是什么意思?
-
如果可能的话,您能否提供一个简短的输入 JSON 文件的 sn-p?我不确定,如果你正确地导入了你的数据,因为你的 DataFrame(甚至可能是一个系列)看起来有点奇怪,只是包含你的 JSON 文件的这些“subdicts”。
标签: python loops pandas selection rows