Try this:
updated_df = (
df.drop(columns=['Day_of_year', 'Month', 'Week_of_year'])
.assign(**{"random": 0, 'timestamp': pd.to_datetime(df['timestamp'])})
)
Testing
Evaluating the above code on a dummy dataframe:
import pandas as pd
# Create a date range
date_range = pd.date_range(start='2023-07-01', end='2023-07-10')
# Create the DataFrame
df = pd.DataFrame()
df['timestamp'] = date_range
df['Day_of_year'] = df['timestamp'].dt.dayofyear
df['Month'] = df['timestamp'].dt.month
df['Week_of_year'] = df['timestamp'].dt.isocalendar().week
updated_df = (
df.drop(columns=['Day_of_year', 'Month', 'Week_of_year'])
.assign(**{"random": 0, 'timestamp': pd.to_datetime(df['timestamp'])})
)
print(updated_df)
# Prints:
#
# timestamp random
# 0 2023-07-01 0
# 1 2023-07-02 0
# 2 2023-07-03 0
# 3 2023-07-04 0
# 4 2023-07-05 0
# 5 2023-07-06 0
# 6 2023-07-07 0
# 7 2023-07-08 0
# 8 2023-07-09 0
# 9 2023-07-10 0