【发布时间】:2017-09-10 18:20:49
【问题描述】:
我有一个这样的 DataFrame:
A B C
1 1 3 5
2 1 3 6
3 2 4 7
4 2 4 8
我知道我可以过滤固定列如下:
df[df[A]==1 & df[B]==3]
但是如果我想通过灵活的dict长度过滤DataFrame:
dict = {'A':1, 'B':3, 'C':5]}或
dict = {'A':2, 'B':4}
我可以得到:
A B C 1 1 3 5或
A B C 3 2 4 7 4 2 4 8
我该如何解决这个问题?
【问题讨论】:
-
我觉得你需要this
标签: python pandas dictionary dataframe