I want to Create a line graph that gives the daily maximum temperature for 2005 in my dataframe and also make the x-axis is a date and covers the whole year. When I run my code, I get this error : SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame.See below my code:
data = pd.read_csv('https://raw.githubusercontent.com/dereksonderegger/444/master/data-raw/FlagMaxTemp.csv')
# Filter data for year 2005
data_2005 = data[data['Year'] == 2005]
# Create a date column combining Year, Month, and Day
data_2005.loc[:, 'Date'] = pd.to_datetime(data_2005[['Year', 'Month']].assign(day=1))
# Set Date as the index
data_2005.set_index('Date', inplace=True)
# Extract the daily maximum temperature columns
max_temp_cols = [str(i) for i in range(1, 32)]
max_temp_data = data_2005[max_temp_cols]
# Reshape the data to long format
max_temp_data = max_temp_data.melt(var_name='Day', value_name='Temperature', ignore_index=False)
max_temp_data.reset_index(inplace=True)
# Convert Day column to integer
max_temp_data['Day'] = max_temp_data['Day'].astype(int)