Home > Software engineering >  Resampling dataframe in Python
Resampling dataframe in Python

Time:06-18

I'm trying to resample and plot the average temperature of a city from a dataframe by year using Pandas. I'm successfully creating a copy of the data however, I keep running into this issue. enter image description here

Note: The column name of the date is dt.

CodePudding user response:

You are telling pandas to look for a column called 'Y' but the KeyError is telling you that this pandas data frame doesn't have a column called 'Y'

Here's a more detailed explanation of the error.

https://www.statology.org/pandas-keyerror/#:~:text=One error you may encounter when using pandas,accidental space before or after the column name.[KeyError][1]

CodePudding user response:

You only save the AverageTemperature column. Try keeping all columns, or at least include the Y column too:

df2 = df[(df['City'] == 'Aden') & (df['Country'] == 'Yemen')].copy()
  • Related