I'm having a hard time getting Pandas resample to work. I don't want to set a datetime index but want to use a column with the dates. As I understood this should be possible. (When using a datetime index it does work)
this is my code:
import pandas as pd
data_in = [
["date","serial","event"],
["2021-08-11","6840","1"],
["2021-08-11","6840","1"],
["2021-08-12","6840","1"],
["2021-08-13","6840","1"],
["2021-08-15","6840","1"],
["2021-08-15","6840","1"],
["2021-08-16","6840","1"],
["2021-08-17","6840","1"],
["2021-08-17","6840","1"],
["2021-08-17","6840","1"],
["2021-08-18","6840","1"],
["2021-08-19","6840","1"],
["2021-08-21","6840","1"],
["2021-08-21","6840","1"],
["2021-09-01","6840","1"],
["2021-09-04","6840","1"],
["2021-09-04","6840","1"],
["2021-09-05","6840","1"],
["2021-09-07","6840","1"],
["2021-09-11","6840","1"],
]
col_names = data_in.pop(0)
work_data = pd.DataFrame(data_in,columns=col_names)
work_data["date"] = pd.to_datetime(work_data["date"])
work_data["event"] = pd.to_numeric(work_data["event"])
sum_data = work_data[["date","event"]]
sum_data = sum_data.resample("W",on=sum_data["date"]).sum()
Resample then trows an exception:
Exception has occurred: ValueError
The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I'm not getting it. What is the error? What am I doing wrong? The documentation does not help me. The tutorials I saw where pretty straight forward and I'm not doing anything fancy.