如果我做对了,您要做的是将 Date 设置为索引:
df.set_index('Date')
I found a better way to import them, because when I was trying to calculate the monthly returns it does not work. So I use this new code and the date were perfect.
df = pd.read_excel('C:/Users/Me/Data.xlsx', sheet_name='Prices')
df.index = pd.to_datetime(df['Date'])
df.drop(['Date'], axis = 'columns', inplace=True)
df.head()
and this is the result:
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.