Pandas select 行基于用户输入的列名和值

Pandas select row based on user input of column names and values

我有一个包含很多列的数据框。 我想 select 根据以下四个变量的用户输入行

如何使用 pandas 解决这个问题?

也许试试这个,

# given col1, val1, col2, val2
result_rows = df[(df[col1] == val1) & (df[col2] == val2)]

你可以看一下如何 select 中的数据 pandas: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html