Apr-25-2020, 10:58 AM
code added
Hi,
I'm trying to group all the value of the dataframe essaie['night_cons'] by day (and by year) but the result just gives me NAN.
please see the image below.
Thks
Hi,
I'm trying to group all the value of the dataframe essaie['night_cons'] by day (and by year) but the result just gives me NAN.
please see the image below.
colss = {'Date_Time': ['2017-11-10','2017-11-11','2017-11-12','2017-11-13', '2017-11-14', '2017-11-15', '2017-11-16', '2017-11-17', '2017-11-18', '2017-11-19'], 'Night_Cons(+)': [4470.76,25465.72,25465.72,25465.72, 21480.59, 20024.53, 19613.29, 28015.18, 28394.20, 29615.69] } dataframe = pd.DataFrame(colss, columns = ['Date_Time', 'Night_Cons(+)']) #print (dataframe) dataframe['Date_Time'] = pd.to_datetime(dataframe['Date_Time'], errors = 'coerce') # Create new columns dataframe['Day'] = dataframe['Date_Time'].dt.day dataframe['Month'] = dataframe['Date_Time'].dt.month dataframe['Year'] = dataframe['Date_Time'].dt.year # Set index #essaie = essaie.set_index('Date_Time') dataframe = dataframe[['Night_Cons(+)', 'Day', 'Month', 'Year']] #dataframe #daily_data = pd.pivot_table(essaie, values = "Night_Cons(+)", columns = ["Month"], index = "Day") daily_data = pd.pivot_table(dataframe, values = "Night_Cons(+)", columns = ["Year"], index = "Day") daily_data = daily_data.reindex(index = ['Montag','Dienstag','Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag']) daily_dataDataFrame and Results
Thks