[Pandas](EN) Change type in DataFrame column


Environment and Prerequisite

  • Python
  • Pandas


Usage

  • Use .astype()
import pandas as pd

df = pd.DataFrame({'A': ['1', '2', '3'], 'B': [4, 5, 6]})

print(df.dtypes)

# convert column 'A' from string to int
df['A'] = df['A'].astype(int)

print(df.dtypes)


Reference