I am trying to resample and plot the AverageTemperature column of a dataframe based on the values of 2 other columns (Country and City) but I keep getting an error that I can't seem to resolve.
Note: dt are dateTime objects
CodePudding user response:
Assuming the column names are Country
and City
, you will want to update your code to:
df2 = df[(df["City"] == "Aden") & (df["Country"] == "Yemen")]["AverageTemperature"].copy()
CodePudding user response:
df2 = df.query("(Country == 'Yemen') & (City == 'Aden')")["AverageTemperature"].copy(deep=True)
If you don't put deep = True, you will have a shallow copy, any changes made on the original will reflect on the copy/copies.