Link Search Menu Expand Document

Subset a df according to string present in columns name

df.loc[:, df.columns.str.startswith('alp')]
df.loc[:, df.columns.str.contains('alp')]

Rename columns

df.rename(columns={'oldName1': 'newName1', 'oldName2': 'newName2'}, inplace=True)

Check df datatype

df.dtypes

Convert to a specific type

df.year.astype(int)