Migration Guide: Pandas 2.x to 3.0

Pandas 3.0 removes many features deprecated during the 2.x series. Here are the major changes to anticipate and the steps to smoothly migrate your code.

Removed Features

The main removals concern methods and parameters deprecated in Pandas 2.x. If your code shows FutureWarning with Pandas 2.2, it will likely break with 3.0.

python
import pandas as pd

# --- REMOVED in Pandas 3.0 ---

# 1. DataFrame.append() -> use pd.concat()
# BEFORE:
# df = df.append({'a': 1}, ignore_index=True)  # removed
# AFTER:
df = pd.DataFrame({'a': [1, 2]})
new_row = pd.DataFrame({'a': [3]})
df = pd.concat([df, new_row], ignore_index=True)

# 2. DataFrame.swaplevel() inplace -> return the result
# 3. Series.swaplevel() inplace -> same

# 4. The 'method' parameter of fillna() is removed
# BEFORE:
# df.fillna(method='ffill')  # removed
# AFTER:
df = df.ffill()

# 5. datetime64[ns] is no longer the default dtype
#    -> datetime64[us] (microsecond) is the new default

Migration Steps

Proceed in three stages: fix warnings with Pandas 2.2, test with CoW mode enabled, then upgrade to Pandas 3.0.

python
# Step 1: Identify deprecations with Pandas 2.2
import warnings
warnings.filterwarnings('error', category=FutureWarning)
# Run your tests: every FutureWarning becomes an error

# Step 2: Enable CoW in Pandas 2.2 to prepare
import pandas as pd
pd.set_option('mode.copy_on_write', True)
# Verify your code still works

# Step 3: Update common patterns

# Replace inplace=True (recommended):
# BEFORE: df.reset_index(inplace=True)
# AFTER:  df = df.reset_index()

# Replace chained assignment:
# BEFORE: df['a'][0] = 99  # no longer works with CoW
# AFTER:  df.loc[0, 'a'] = 99

# Step 4: pip install pandas>=3.0 and rerun tests

Sources