简体   繁体   English

熊猫在csv文件中分组列

[英]Group column in csv file by pandas

I have data 我有资料

ID,"day"
00051f002f5a0c179d7ce191ca2c6401,2016-03-01
00051f002f5a0c179d7ce191ca2c6401,2016-03-06
000700651343ff73c10212a095ab4091,2016-03-06
000700651343ff73c10212a095ab4091,2016-03-01
00102b98bd9e71da3cf23fd1f599408d,2016-03-01

I try to print to every data list of unique users 我尝试打印到唯一用户的每个数据列表

df = pd.read_csv("users.csv")
df = df.groupby('day')['ID'].unique().reset_index(name="unique")
users = df["unique"]
for elem in users:
    print elem

and get 并得到

['00051f002f5a0c179d7ce191ca2c6401' ..., '00102b98bd9e71da3cf23fd1f599408d']
['00051f002f5a0c179d7ce191ca2c6401' ..., '000700651343ff73c10212a095ab4091']

They not delimited with , and there are not all values, instead this in contain ... . 它们不以分隔,也不是所有值,而是包含在... How can I change that and get lists? 我该如何更改并获取列表?

Those are numpy arrays, and the ... is just because the list is long and numpy has a feature where it doesn't show you every element if the list is too long. 这些是numpy数组,而...只是因为列表很长,而numpy具有一项功能,如果列表太长,它不会向您显示每个元素。 The elements are there. 元素在那里。

If you want a list you can just use list(elem) 如果您想要一个列表,可以只使用list(elem)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM