replace the column names of “begindatumtijd” and “einddatumtijd” by “begin” and “end”. in python

You can rename the column names using pandas rename() function.

Assuming you have a pandas DataFrame df with columns named "begindatumtijd" and "einddatumtijd", you can rename them to "begin" and "end" using the following code:

main.py
import pandas as pd

df = pd.read_csv("your_csv_file.csv")
df = df.rename(columns={"begindatumtijd": "begin", "einddatumtijd": "end"})
print(df.head())
152 chars
6 lines

This will print the first five rows of the DataFrame with the new column names. If you want to modify the original DataFrame, you can add the inplace=True argument to rename() function.

main.py
df.rename(columns={"begindatumtijd": "begin", "einddatumtijd": "end"}, inplace=True)
print(df.head())
102 chars
3 lines

This will rename column names in place.

related categories

gistlibby LogSnag