Python 类型错误:不可损坏的类型:';列表';?尝试对数据帧进行切片时

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]] 即,丢失括号

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]
错:

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