Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.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
Python 如何访问具有特殊字符名称的数据帧中的列_Python_Python 3.x_Dataframe_Multiple Columns_Columnname - Fatal编程技术网

Python 如何访问具有特殊字符名称的数据帧中的列

Python 如何访问具有特殊字符名称的数据帧中的列,python,python-3.x,dataframe,multiple-columns,columnname,Python,Python 3.x,Dataframe,Multiple Columns,Columnname,我有一个带有列名的数据框,其中包含特殊字符,如 Date ('Date','') ('Max_Bid_Price', 'ALBAN') 问题是当我试图删除('Date','')列时,它抛出了错误 我试过了 df["('Date','')"] # not able to find the label df["\(\'Date\'\,\'\'\)"] # not able to find the label 但是当我试着 data.columns[1] # i got the

我有一个带有列名的数据框,其中包含特殊字符,如

Date    
('Date','') 
('Max_Bid_Price', 'ALBAN')  
问题是当我试图删除('Date','')列时,它抛出了错误

我试过了

df["('Date','')"]   # not able to find the label
df["\(\'Date\'\,\'\'\)"] # not able to find the label
但是当我试着

data.columns[1] # i got the column value as output
data.drop(data.columns[1],axis=0) # but it still throws an error: "labels [('Date', '')] not contained in axis"

有谁能帮助我如何访问名为的列(因为我必须对其进行操作)并删除这些列:

如果您尝试删除列,则轴应为1

data.drop(data.columns[1],axis=1)
您可以使用:


恐怕落差不合适:

df=df.drop(“('Date',''”),axis=1)
或者:

df=df.drop(columns=“('Date',”))

df['(\'Date\',\'\')']。这样行吗?请提供一个。为什么名字一开始就是这样的?根据你写的,第一次尝试应该有效。第二个代码段由于轴参数不正确而失败,您应该阅读文档。它与df.drop(('Date',''),axis=1)有何不同?实际上结果是一样的……你是对的,在这种情况下,
r
没有添加任何内容,因为它在“反斜杠”上工作。
df.drop(r"('Date','')", axis=1)