我正在使用此命令匯入資料
df = pd.read_excel('C:/Users/Me/Data.xlsx', sheet_name='Prices')
這是結果:

日期是一個常見的列,我希望它是這樣的:

uj5u.com熱心網友回復:
如果我做對了,您要做的是將 Date 設定為索引:
df.set_index('Date')
uj5u.com熱心網友回復:
我找到了 answer.Adding parse_dates=True,index_col=0像這樣的匯入命令:
df = pd.read_excel('C:/Users/Me/Data.xlsx', sheet_name='Prices', parse_dates=True, index_col=0)
輸出是這樣的:

uj5u.com熱心網友回復:
我找到了一種更好的方法來匯入它們,因為當我試圖計算每月回報時它不起作用。所以我使用了這個新代碼,日期很完美。
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()
這是結果:
有名氣的人幫我畫圖:)謝謝
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/474766.html
