I added a datetime
to my data and I want to get rid of the old one, so it looks cleaner! Is it possible to change the title from data.dataset
to something else?
I tried df.rename(columns={"data.datasets":"mydata"}) but unfortunately no changes :(
import datetime
#convert the column to datetime:
df["data.date"] = pd.to_datetime(df["data.date"])
df["date"] = df["data.date"].apply(lambda x : x.date())
df.date = pd.to_datetime(df.date)
df.set_index('date', inplace=True)
# First for the day:
df = df.resample('d').first()
# Print only 5/05 - 6/05
print(df.loc[df.index.to_series().between('2022-05-05', '2022-06-05')])
This is what the data currently looks like:
data.date data.datasets Time date
2022-05-05 2022-05-05 04:19:35 3.0500 2022-05-05
2022-05-06 2022-05-06 00:10:24 2.3500 2022-05-06
2022-05-07 2022-05-07 00:10:47 4.0900 2022-05-07
2022-05-08 2022-05-08 00:08:13 3.8790 2022-05-08
2022-05-09 2022-05-09 00:13:24 3.5780 2022-05-09
2022-05-10 2022-05-10 00:08:49 3.7500 2022-05-10
2022-05-11 2022-05-11 00:09:33 4.3900 2022-05-11
2022-05-12 2022-05-12 00:08:24 3.6900 2022-05-12
2022-05-13 2022-05-13 00:08:45 3.4300 2022-05-13
2022-05-14 2022-05-14 00:08:55 3.9500 2022-05-14
CodePudding user response:
Renaming the column(s) by providing a dictionary {}:
df.rename(columns={"data.datasets":"mydata"})
Removing a column:
df.drop(columns="data.date", inplace=True)