美文网首页python学习笔记
python:A value is trying to be s

python:A value is trying to be s

作者: 书生_Scholar | 来源:发表于2020-05-15 09:23 被阅读0次

    1.运行一段代码,出现警示错误,但是程序还是正常运行

    file_hw = file[file["厂家"] == "华为"]
    file_hw["ECI"] = file_hw.loc[:, "ENODEB"].astype(str) + "-" + file_hw.loc[:, "小区标示"].astype(str)
    
    • 错误如下:
    SettingWithCopyWarning: 
    A value is trying to be set on a copy of a slice from a DataFrame.
    Try using .loc[row_indexer,col_indexer] = value instead
    # 。。。。。。。。省略部分错误
    
    • 解决方案:
    file_hw = file[file["厂家"] == "华为"]
    x = file_hw.copy
    x["ECI"] = x.loc[:, "ENODEB"].astype(str) + "-" + x.loc[:, "小区标示"].astype(str)
    
    # This warning comes because your dataframe x is a copy of a slice. This is not easy to know why, but it has something to do with how you have come to the current state of it.
    # You can either create a proper dataframe out of x by doing
    x = x.copy()
    # This will remove the warning, but it is not the proper way
    # You should be using the DataFrame.loc method, as the warning suggests, like this:
    x.loc[:,'Mass32s'] = pandas.rolling_mean(x.Mass32, 5).shift(-2)
    
    

    相关文章

      网友评论

        本文标题:python:A value is trying to be s

        本文链接:https://www.haomeiwen.com/subject/cwyqohtx.html