Answers for "change the name of two column in pandas"

1

pandas rename multiple columns

# df is a pandas DataFrame

for col_name in df.columns:
  # you can specify conditions if you need 
  # to change the name of some column only
  df = df.rename(columns = {col_name:new_col_name}
Posted by: Guest on May-31-2021
1

pandas change multiple column types

#Two ways to do this
df[['parks', 'playgrounds', 'sports']].apply(lambda x: x.astype('category'))

cols = ['parks', 'playgrounds', 'sports', 'roading']:
public[cols] = public[cols].astype('category')
Posted by: Guest on November-27-2020

Code answers related to "change the name of two column in pandas"

Python Answers by Framework

Browse Popular Code Answers by Language