import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import datetime
pf_value=pd.read_excel(r'C:\Users\Kaixin Feng\Downloads\rawdata.xlsx')
pf_value = pf_value.astype(float)
market = pd.read_excel(r'C:\Users\Kaixin Feng\Downloads\market.xlsx')
market = market.astype(float)
data = [pf_value,market]
for i in range(len(data)):
data[i].set_index(['date'],inplace=True)
data[i].iloc[:,0]=data[i].iloc[:,0].astype(float)
print(data[0])
结果出现:
File "C:\Users\Kaixin Feng\anaconda3\lib\site-packages\pandas\core\arrays\datetimelike.py", line 424, in astype
raise TypeError(msg)
TypeError: Cannot cast DatetimeArray to dtype float64
源数据:
market.xlsx:
rawdata.xlsx: