jeudi 3 octobre 2019

Python if elif else statement errors

I convert a string of the style "2019-08-04" into a day of the week. Then I am using this string as the input to my if elseif else block of code. In my else if I assigning a certain dataframe to another dataframe. I keep getting two errors "ValueError: Wrong number of items passed 3, placement implies 96" and "ValueError: Cannot set a frame with no defined index and a value that cannot be converted to a Series". The type of monAverages and the rest below is "pandas.core.frame.DataFrame". The type of dayOfWeek is "str". Thank you for your help!

Python

'''

date = "2019-08-04"
dayOfWeek =(pd.to_datetime(date)).day_name()

if dayOfWeek == "Monday":
    df_new2['kW'] = monAverages
elif dayOfWeek == "Tuesday":
     df_new2['kW'] = tuesAverages
elif dayOfWeek == "Wednesday":
     df_new2['kW'] = wedAverages
elif dayOfWeek == "Thursday":
     df_new2['kW'] = thursAveraes
elif dayOfWeek == "Friday":
     df_new2['kW'] = friAverages
elif dayOfWeek == "Saturday":
     df_new2['kW'] = satAverages
else: 
    df_new2['kW'] = sunAverages

'''

Aucun commentaire:

Enregistrer un commentaire