python筛选出csv满足某条件的行,如何通过在python中的某些列上应用条件来过滤csv数据...

I am new python data analysis and having some problems to get the required data in specific format.

My data is in following format. ( please check the attached link for data in csv format as the data is quite large)

0fb7a699c2beccbb6a2584ee5d245877.png

I used following commands to print the csv data in the above format

address = 'C:\Barchatdata.csv'

data_c = pd.read_csv(address)

Now i want to apply if condition on Energy_Supply_per_capita >280 and then print index column, contry_area, Energy_Supply_per_capita and Avg_GDP columns.

i tried following command

data_c.loc[data_c['Energy_Supply_per_capita'] > 280, 'Energy_Supply_per_capita']

but got only index and Energy_Supply_per_capita columns.

How i can get the required results?

Thank you in advance.

解决方案

You can use query

cols = ['Country_Area', 'Energy_Supply_per_capita', 'Avg_GDP']

data_c.query('Energy_Supply_per_capita > 280')[cols]

Or equivalently with a boolean series and loc

cols = ['Country_Area', 'Energy_Supply_per_capita', 'Avg_GDP']

data_c.loc[data_c.Energy_Supply_per_capita > 280, cols]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值