Home > Software design >  Change timedelta64[ns[ to string
Change timedelta64[ns[ to string

Time:04-10

I have both Date and Time which is being imported from MySQL. The Date column is object type while Time is timedelta64[ns] type. I wanted to combine them and put it as an index column on the DataFrame, so that I could put it as x-axis labels in the graphs. I tried a lot of ways but nothing seems to work out for me. Is there any way to do this effectively?

CodePudding user response:

We first have to cast the object type to a datetime object:

df['Date'] = pd.to_datetime(df['Date'])

Then we can just add the time difference to the date by using:

df['Datetime'] = df['Date']   df['Time']
  • Related