数据:
id_num House Color
6589 Smith yellow
6589 Cordero pink
6589 Martinez brown
6589 Rossi black
8956 Portella green
8956 Fusco purple
8956 Benito white
1064 Dimingo red
1064 Martinez indigo
1064 Schultz violet
我需要通过以这种方式将id_num与pandas
分组来创建列表id_list =(6589,8956,1064)
答案 0 :(得分:1)
您似乎需要unique
或drop_duplicates
并转换为tuple
:
a = tuple(df.id_num.unique())
a = tuple(df.id_num.drop_duplicates())
print (a)
(6589, 8956, 1064)
print (type(a))
<class 'tuple'>
如果想要list
:
b = df.id_num.unique().tolist()
b = df.id_num.drop_duplicates().tolist()
print (b)
[6589, 8956, 1064]
print (type(b))
<class 'list'>