Using Python (pandas as pd) I am trying to use the split, apply, combine method but am getting an "invalid syntax" error at the end of the line that says "for days_name, days_df in grouped_by_day" I declared grouped_by_day in the split function but did not get any errors so I am not sure what happened or how to fix it. Below is a copy of the split, apply, combine section of my code.
mean_data_ser = pd.Series()
#split
grouped_by_day= days_df.groupby("Day of Week")
#apply
for days_name, days_df in grouped_by_day (This is the line where I get the error)
mean_functionality= days_df["Day of Week"].mean()
print (mean_functionality)
#combine
mean_functionality_ser[str(days_name)]= mean_functionality
print mean_functionality_ser
In the given code there are few errors.
for days_name, days_df in grouped_by_day you have to put colon at the end of this statement.
mean_functionality= days_df["Day of Week"].mean() this line is indented wrongly so move this line.and
print mean_functionality_ser missing paranthesis
The print statement must have paranthesis to display output.
The below code fix these three errors.
Code:
mean_data_ser = pd.Series()
#split
grouped_by_day= days_df.groupby("Day of Week")
#apply
for days_name, days_df in grouped_by_day: #(This is the line where I get the error)
mean_functionality= days_df["Day of Week"].mean()
print (mean_functionality)
#combine
mean_functionality_ser[str(days_name)]= mean_functionality
print (mean_functionality_ser)
Get Answers For Free
Most questions answered within 1 hours.