Python 类型错误:不可损坏的类型:';列表';?尝试对数据帧进行切片时
My告诉我们,在数据框中选择特定值的方法是键入:Python 类型错误:不可损坏的类型:';列表';?尝试对数据帧进行切片时,python,pandas,Python,Pandas,My告诉我们,在数据框中选择特定值的方法是键入: df.loc([row,column]) 或 但当我尝试执行此操作时,我收到以下错误消息: “TypeError:不可损坏的类型:'list'” 怎么了 很难说没有一个明确的例子,但我认为你有: file.loc([row,column]) # and file.loc([[row],[column]]) 您可能想要: file.loc[row,column] # and file.loc[[row],[column]] 即,丢失括号
df.loc([row,column])
或
但当我尝试执行此操作时,我收到以下错误消息:
“TypeError:不可损坏的类型:'list'”
怎么了 很难说没有一个明确的例子,但我认为你有:
file.loc([row,column])
# and
file.loc([[row],[column]])
您可能想要:
file.loc[row,column]
# and
file.loc[[row],[column]]
即,丢失括号。否,切片数据帧的正确语法为:
df.loc[row,column]
错:
df.loc([row,column])
^ ^ # no parentheses () around the [...] expression
df.loc([[row],[column]])
^ ^ ^ ^ ^ ^ # no second pair of [] brackets, and no parentheses
假设这就是你想要访问的。CSV只是一种文件格式,不是对象df=pd.read_csv(…)
读取csv文件并将其分配给名为df
的数据帧
- 数据帧称为数据帧,而不是“包含csv的变量”。通常按照惯例,我们会给他们变量名
df,df2,df\u b…
行
和列
,或者它们有什么值。假设你的问题是关于熊猫数据帧的,但你没有在标题或标记的任何地方说,在正文中你也没有显示你的数据帧或代码。(如果显示前一行代码,可能会有所帮助,df=pd.read\u csv(…)
)。如果这不是你想要的,那么请编辑问题以更清楚地重申。
df.loc([row,column])
^ ^ # no parentheses () around the [...] expression
df.loc([[row],[column]])
^ ^ ^ ^ ^ ^ # no second pair of [] brackets, and no parentheses