首页 > 解决方案 > Pandas - 根据变量值过滤数据框

问题描述

我有一个存储索引值的变量。我正在尝试根据存储在此变量中的值过滤数据框。

下面给出了这些值的方式:

var = 2  <-- this stores the value for the variable. Now I am trying to create a copy of the Dataframe with only this column.

下面给出了我的数据框是如何的:

0,1,2,3,4
apple,4,3,4,5
orange,3,4,5,6
bananas,5,3,5,6

由于变量值为var = 2,我正在尝试创建一个只有第二列的新数据框。下面给出了预期的输出:

2
3
4
3

标签: pandasdataframe

解决方案


推荐阅读