简体   繁体   中英

Python automatically converts number to date

I am dropping some numerical values in a column using the following code, but then it somehow changes all the numerical values to date type, which is not what I need. I cannot see how to fix it, so I would really appreciate if some of you could help fix this error for me.

df = pd.read_csv(datapath+"CompleteOrder_HANOI_Alltime.csv") 
df = df.drop(df[df.completed_orders == 0].index)
df = df.dropna(subset = ["completed_orders"])
df['y'] = np.log(df['completed_orders'])

df['y'] = df.drop(df[df.y <= 0].index)
df = df.drop('completed_orders', axis = 1)
df = df.drop('percent_completed', axis = 1)
df['ds'] = df['to_char']
df = df.drop('to_char', axis = 1)
df['ds'] = pd.to_datetime(df['ds'])

Your last statement converts df['ds'] to datetime. Add a print statement of df['ds'] to see what's being converted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM