在CSV中使用熊猫

时间:2019-09-21 00:46:14

标签: python pandas

我是Python的新手,请帮助我理解并继续进行python学习。在示例数据下方找到:

Country Age Sal OnWork
USA 52 12345 No
UK 23 1142 Yes
MAL 25 4456 No

如果OnWork为否,我想在SAL列中找到平均值

1 个答案:

答案 0 :(得分:1)

假设您的数据如下所示,

{'Country': 'USA', 'Age': '52', 'Sal': '12345', 'OnWork': 'No'}
{'Country': 'UK', 'Age': '23', 'Sal': '1142', 'OnWork': 'Yes'}
{'Country': 'MAL', 'Age': '25', 'Sal': '4456', 'OnWork': 'No'}

以下代码对您有帮助:

df = your_dataframe
df[df["OnWork"]=="No"]["Sal"].mean()