How to fix AttributeError- 'Int64Index' object has no attribute 'month'?
Quick answer
This means you called a datetime accessor like .month on an integer index. Datetime accessors only exist on datetime-typed objects, so convert first with df.index = pd.to_datetime(df.index), or use pd.to_datetime(df['date']).dt.month for a column. Note that Int64Index itself was removed in pandas 2.0 — use pd.api.types.is_integer_dtype() instead of isinstance checks.
The Problem
The AttributeError: 'Int64Index' object has no attribute 'month' error is raised when you try to access the month attribute of an object that has an Int64Index type. This is most likely to occur when working with data in a Pandas DataFrame, as the Index of a DataFrame is often of type Int64Index.
The Solution
To fix this error, you will need to make sure that you are only trying to access the month attribute of objects that have this attribute. One way to do this is to check the type of the object before trying to access the month attribute.
For example:
import pandas as pd
# Load some data into a DataFrame
df = pd.read_csv('data.csv')
# Check the type of the index
if isinstance(df.index, pd.Int64Index):
print("The DataFrame has an Int64Index.")
else:
print("The DataFrame does not have an Int64Index.")
# Try to access the month attribute (this will raise an AttributeError)
try:
month = df.index.month
except AttributeError:
print("The DataFrame index does not have a 'month' attribute.")
Alternatively, you could use the pd.DatetimeIndex type for the index of your DataFrame, as this type does have a month attribute. To do this, you can convert the index of your DataFrame to a DatetimeIndex using the pd.to_datetime() function:
import pandas as pd
# Load some data into a DataFrame
df = pd.read_csv('data.csv')
# Convert the index to a DatetimeIndex
df.index = pd.to_datetime(df.index)
# Now you can access the month attribute without raising an AttributeError
month = df.index.month
Related: this is one of a handful of recurring pandas pitfalls. See the common pandas errors and gotchas guide for the view-vs-copy, index-type, and alignment concepts behind most of them.
Software Engineering Leader & Technical Author · Updated July 21, 2026