Correct way to set new column in pandas DataFrame to avoid SettingWithCopyWarning

后端 未结 3 2064
别那么骄傲
别那么骄傲 2021-02-05 01:15

Trying to create a new column in the netc df but i get the warning

netc[\"DeltaAMPP\"] = netc.LOAD_AM - netc.VPP12_AM

C:\\Anaconda\\lib\\site-packages\\ipykerne         


        
3条回答
  •  甜味超标
    2021-02-05 01:58

    You need to reset_index when you will create column especially if you have filtered on specific values... then you don't need to use .loc[row_indexer,col_indexer]

    netc.reset_index(drop=True, inplace=True)
    netc["DeltaAMPP"] = netc.LOAD_AM - netc.VPP12_AM
    

    Then it should work :)

提交回复
热议问题