Welcome to StackOverflow! It can be helpful for us to see a minimal reproducible example that demonstrates your error. Otherwise we have to make additional, potentially incorrect, assumptions.
For what you have provided, it looks like Pandas is giving you a TypeError
, indicating that Pandas received a incompatible data types for the comparison operation <
. Trying to use a less than operation on a string and an integer can produce the same error:
>>> '2' < 2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: '>' not supported between instances of 'str' and 'int'
The .dtypes
method shows the data types for each column in your DataFrame
. If your date
column is listed as object
this means it is a string and not a date. If so, you can see this answer on how to convert a string to a date. (When reading input from .csv
files I often forget to apply the parse_date=
keyword of pd.read_csv
).
Here's a functional example of .resample()
. The docs for resample do not state it clearly that I can tell, but one tricky aspect is that the date values must be in the index, which you can accomplish using .set_index('date')
.
import pandas as pd
import numpy as np
# create dataframe with on value per day
days = pd.date_range(start='2022-01-01', end='2022-01-31', freq='D')
counts = np.arange(days.shape[0])
df = pd.DataFrame(data={'date': days, 'count':counts})
# resample to sum over each week
df.set_index('date').resample('W').sum()