This behavior seems odd to me: the id
column (a string) gets converted to a timestamp upon transposing the df
if the other column is a timedelta.
import pandas as pd
df = pd.DataFrame({'id': ['00115', '01222', '32333'],
'val': [12, 14, 170]})
df['val'] = pd.to_timedelta(df.val, unit='Minutes')
print(df.T)
# 0 1 2
#id 0 days 00:00:00.000000 0 days 00:00:00.000001 0 days 00:00:00.000032
#val 365 days 05:49:12 426 days 02:47:24 5174 days 06:27:00
type(df.T[0][0])
#pandas._libs.tslib.Timedelta
Without the timedelta it works as I'd expect, and the id
column remains a string, even though the other column is an integer and all of the strings could be safely cast to integers.
df2 = pd.DataFrame({'id': ['00115', '01222', '32333'],
'val': [1, 1231, 1413]})
type(df2.T[0][0])
#str
Why does the type of id
get changed in the first instance, but not the second?