问题:
This question already has an answer here: 这个问题在这里已有答案:
Lets say I have the following pandas dataframe: 假设我有以下pandas数据帧:
df = DataFrame({'A' : [5,6,3,4], 'B' : [1,2,3, 5]})
df
A B
0 5 1
1 6 2
2 3 3
3 4 5
I can subset based on a specific value: 我可以根据特定值进行子集化:
x = df[df['A'] == 3]
x
A B
2 3 3
But how can I subset based on a list of values? 但是我如何根据值列表进行子集化? - something like this: - 这样的事情:
list_of_values = [3,6]
y = df[df['A'] in list_of_values]
解决方案:
参考一: https://stackoom.com/question/okmq/使用值列表从pandas数据框中选择行-duplicate参考二: https://oldbug.net/q/okmq/Use-a-list-of-values-to-select-rows-from-a-pandas-dataframe-duplicate
来源:oschina
链接:https://my.oschina.net/u/4432649/blog/4422361