我想从 CSV 文件中选择数据。
虽然我可以得到哪一列的数据
"House" == 1 (any single number)
如下,我不知道如何从哪里获取数据
"House" in [1, 2, 3, 4, 6, 7, 8, 9, 10, 13, 17, 18, 20, 21, 23, 26, 28, 30, 34, 46, 57, 58, 61, 86, 89, 102, 121, 156].
df = pd.read_csv('../../data/training_dataset_500.csv')
df[df['House']==1]
Series.isin()
方法检查系列值是否在值列表中。就你而言 -
df[df['House'].isin([1, 2, 3, 4, 6, 7, 8, 9, 10, 13, 17, 18, 20, 21, 23, 26, 28, 30, 34, 46, 57, 58, 61, 86, 89, 102, 121, 156])]
示例-
In [77]: df
Out[77]:
A B
0 1 5
1 2 6
2 3 7
3 4 8
In [78]: df[df['A'].isin([1,2])]
Out[78]:
A B
0 1 5
1 2 6