python删除满足条件的行_使用Python删除满足两个特定条件(值)的数据框行

本文展示了如何使用Python的pandas库删除数据框中年龄大于25岁或体重超过200磅的行。通过将条件组合在一行代码中,实现了数据过滤。
摘要由CSDN通过智能技术生成

我希望能够保留有关<= 25岁且<= 200磅的球员的信息。

这是我所做的:

代码1:

# importing pandas as pd

import pandas as pd

data = {'Nage':['John Doe', 'Billy Bob', 'Franky Bill'],

'Age':['27','25','27'],

'Weight':['210','185','220']}

df = pd.DataFrame(data)

df['Age']=df['Age'].astype(str).astype(float)

df['Weight']=df['Weight'].astype(str).astype(float)

# Visualize the dataframe

print(df.head())

# Print the shape of the dataframe

print(df.shape)

预期输出1:

Nage Age Weight

0 John Doe 27.0 210.0

1 Billy Bob 25.0 185.0

2 Franky Bill 27.0 220.0

(3, 3)

代码2:

# Filter all rows for which the player's

# age is less than or equal to 25 and weight less than or equ

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值