熊猫 - 寻找行部分的方法

问题描述 投票:-1回答:1

我是大熊猫的新手,我偶然发现了一个数据集,其中包含了从1990年到2017年季节性的Kings County的失业率。目前数据框看起来像这样:Image of my current dataset

虽然没有显示,但该清单一直持续到1990年。我能做些什么才能找到每年的所有月份来找出每年的平均失业率?

我为可怜的问题格式道歉是否会有一个代码将输出面积,年份和失业率?谢谢

python pandas mean
1个回答
0
投票

如果你的数据框被称为df

# Make a new column with unemployment rate as a float, rather than a formatted string with % symbol
df['Unemployment Rate float'] = df['Unemployed'] / df['Labor Force']

# Group by year, and get the mean of the "unemployment rate float" column
df.groupby('Year').mean()['Unemployment Rate Float']

我可以建议pandas tour

© www.soinside.com 2019 - 2024. All rights reserved.