SettingWithCopyWarning: 试图在DataFrame的切片副本上设置一个值
Jupyter Notebook Python 3.7,我已经尝试阅读文档中的警告和类似的问题,但仍然无法理解(抱歉)
def randomTime():
rtime = int(rd.random()*86400)
hours = int(rtime/3600)
minutes = int((rtime - hours*3600)/60)
time_string = '%02d:%02d' % (hours, minutes)
return time_string
df1=pd.DataFrame(0, index=np.arange(10), columns=['time'])
for i in range(10):
df1.time[i]=randomTime()
df1.time=df1.time.str.split(':')
df1['y']=pd.Series(0, index=df1.index)
df2 = pd.DataFrame(np.random.rand(10,1)*10, columns=list('T'))
for i in df1.index:
df1['y'][i]=(float(df1.time[i][0])*60+float(df1.time[i] [1]))/720*math.pi*(20-df2.T[i])
我的df1.Y结果符合预期,但是还有什么更好的编码方式来避免出现警告?