FutureWarning: pandas.Int64Index is deprecated and will be removed from pandas in a future version.

Diagram of pandas.Int64Index is deprecated and will be removed from pandas in a future version

Diagram

“FutureWarning: pandas.Int64Index is deprecated and will be removed from pandas in a future version” error means that the Int64Index class in the pandas library is deprecated and will eventually be removed.

The “Int64Index class was deprecated in version 1.1.0 of the Pandas library, and it is scheduled to be removed in version 1.3.0.” This means that you should not use the Int64Index class in new code, and you should migrate any existing code that uses the Int64Index class to use the Index class instead.

Reproduce the FutureWarning

import pandas as pd

# Create an Int64Index
index_old = pd.Int64Index([1, 2, 3])

# Print the Index
print(index_old)

Output

Reproduce the FutureWarning

How to fix it?

In most cases, you don’t need to explicitly create an Int64Index. You can simply pass a list of integers, and pandas will automatically create an appropriate index.

Here’s an example of how you can create a Pandas Series or DataFrame without explicitly using Int64Index:

import pandas as pd

# Create a Series with an integer index
series = pd.Series([10, 20, 30], index=[1, 2, 3])

# Print the Series
print(series)

# Create a DataFrame with an integer index
df = pd.DataFrame({'value': [10, 20, 30]}, index=[1, 2, 3])

# Print the DataFrame
print(df)

Output

pandas.Int64Index is deprecated and will be removed from pandas in a future version

The Series and DataFrame in this example will have an integer index, but without explicitly using the Int64Index class.

I hope your warning is fixed now!

Related posts

FutureWarning: elementwise comparison failed; returning scalar, but in the future will perform elementwise comparison

AttributeError: ‘DataFrame’ object has no attribute ‘append’

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.