0

SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame

Jupyter Notebook Python 3.7, I have tried read caveats in the documentation and similar question but still don't get it (sorry)

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])

I have df1.Y result as expected but is there any better way to code to avoid warnings ?

0 Answers0