构造测试数据:
import pandas as pd df = pd.DataFrame({'Q':['LI','ZHANG','ZHANG','LI','WANG'], 'A' : [1,1,1,2,2], 'B' : [1,-1,0,1,2], 'C' : [3,4,5,6,7]}) print(df)
数据输出结果:
Q A B C 0 LI 1 1 3 1 ZHANG 1 -1 4 2 ZHANG 1 0 5 3 LI 2 1 6 4 WANG 2 2 7
打印测试数据中特定列的所有值
a=list(dict(df.groupby('Q').groups).keys()) print(a)
数据输出结果:
['LI', 'WANG', 'ZHANG']