How do I use within / in operator in a Pandas DataFrame?
本问题已经有最佳答案,请猛点这里访问。
我想从我的csv文件中选择数据。
尽管我可以在哪个列中获取数据
1 | "House" == 1 (any single number) |
如下所示,我不知道如何获取数据
1 | "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]. |
1 2 | df = pd.read_csv('../../data/training_dataset_500.csv') df[df['House']==1] |
使用
1 | 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])] |
示例-
1 2 3 4 5 6 7 8 9 10 11 12 13 | 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 |