Hey all,
I have the following code below:
TypeError: invalid type promotion
And I'm struggling to understand why?
I have the following code below:
from datetime import datetime import pandas as pd import matplotlib.pyplot as plt data = pd.read_csv('data/C2A2_data/BinnedCsvs_d400/fb441e62df2d58994928907a91895ec62c2c42e6cd075c2700843b89.csv') newdata = data[(data['Date'] >= '2005-01-01') & (data['Date'] <= '2014-12-12')] datamax = newdata[newdata['Element']=='TMAX'] datamin = newdata[newdata['Element']=='TMIN'] datamax = datamax.groupby('Date').max() datamin = datamin.groupby('Date').min() datamax = datamax.reset_index() datamin = datamin.reset_index() datamax = datamax[~datamax['Date'].str.contains("02-29")] datamin = datamin[~datamin['Date'].str.contains("02-29")] breakoutdata = data[(data['Date'] > '2014-12-31')] datamax2015 = breakoutdata[breakoutdata['Element']=='TMAX'] datamin2015 = breakoutdata[breakoutdata['Element']=='TMIN'] datamax2015 = datamax2015.groupby('Date').max() datamin2015 = datamin2015.groupby('Date').min() datamax2015 = datamax2015.reset_index() datamin2015 = datamin2015.reset_index() datamax2015 = datamax2015[~datamax2015['Date'].str.contains("02-29")] datamin2015 = datamin2015[~datamin2015['Date'].str.contains("02-29")] datamin['Date'] = pd.to_datetime(datamin['Date']) datamin2015['Date'] = pd.to_datetime(datamin2015['Date']) datamin["day_of_year"] = datamin["Date"].dt.dayofyear datamin2015["day_of_year"] = datamin2015["Date"].dt.dayofyear dataminappend = datamin2015.join(datamin,on="day_of_year",rsuffix="_new") lower = dataminappend.loc[dataminappend["Data_Value_new"]>dataminappend["Data_Value"]] datamax['Date'] = pd.to_datetime(datamax['Date']) datamax2015['Date'] = pd.to_datetime(datamax2015['Date']) datamax["day_of_year"] = datamax["Date"].dt.dayofyear datamax2015["day_of_year"] = datamax2015["Date"].dt.dayofyear datamaxappend = datamax2015.join(datamax,on="day_of_year",rsuffix="_new") upper = datamaxappend.loc[datamaxappend["Data_Value_new"]<datamaxappend["Data_Value"]] ax = plt.gca() plt.plot(datamax['Date'],datamax['Data_Value'],color='red') plt.plot(datamin['Date'],datamin['Data_Value'], color='blue') plt.scatter(upper['Date'],upper['Data_Value'],color='red') plt.scatter(lower['Date'],lower['Data_Value'], color='blue') plt.ylabel("Temperature (degrees C)",color='navy') plt.xlabel("Date",color='navy',labelpad=15) plt.title('Record high and low temperatures by day (2005-2014)', alpha=1.0,color='brown',y=1.08) ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.35), fancybox=False,labels=['Record high','Record low']) plt.xticks(rotation=30) plt.fill_between(range(len(datamax['Date'])), datamax['Data_Value'], datamin['Data_Value'],color='yellow',alpha=0.8) plt.show()However, I keep getting the error:
TypeError: invalid type promotion
And I'm struggling to understand why?