Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pandas 获取属性错误:';str';对象没有属性loc_Pandas_String_Attributeerror_Loc - Fatal编程技术网

Pandas 获取属性错误:';str';对象没有属性loc

Pandas 获取属性错误:';str';对象没有属性loc,pandas,string,attributeerror,loc,Pandas,String,Attributeerror,Loc,执行此代码时,我得到AttributeError:“str”对象没有属性“loc”。如何解决此错误?似乎: 您有一个名为raw_data的字符串变量 通过这个变量,您创建了一个数据帧(例如,命名为df) 您尝试检索一些数据(从“感染”列中, 从前20行开始) 但是您没有从df检索这些数据,而是尝试 从保存原始数据(字符串)的变量中检索它们 另一种可能的情况是,前一段时间的原始数据是一个数据帧, 但是由于代码中的一些错误,您已经用一些文本覆盖了它 内容 在出现问题的指令之前添加打印(键入(

执行此代码时,我得到AttributeError:“str”对象没有属性“loc”。如何解决此错误?

似乎:

  • 您有一个名为raw_data的字符串变量

  • 通过这个变量,您创建了一个数据帧(例如,命名为df)

  • 您尝试检索一些数据(从“感染”列中, 从前20行开始)

  • 但是您没有从df检索这些数据,而是尝试 从保存原始数据(字符串)的变量中检索它们

  • 另一种可能的情况是,前一段时间的原始数据是一个数据帧, 但是由于代码中的一些错误,您已经用一些文本覆盖了它 内容

    在出现问题的指令之前添加
    打印(键入(原始数据))
    。 结果可能是str(一个字符串)


    然后分析写入原始数据变量时的每种情况。

    您能否分享
    原始数据
    是如何定义/初始化的?
    infections = []
    
    for i in range(0, 20):
        read_nii(raw_data.loc[i,'infection_mask'], infections, 'infections')