重命名df.columns中的值



假设我有一个数据帧列值,如下所示

print(df.columns)
Index([  "CustomerID",  "CompanyName",  "ContactName", "ContactTitle",
"Address",         "City",       "Region",   "PostalCode",
"Country",        "Phone",          "Fax"],
dtype='object')

我想删除值中的引号。这就是我尝试过的:

for cols in list(df.columns):
new_col = str(cols).replace('"','').replace('"','')
cols.rename(index={cols: new_col})

任何解决方案都将是有益的。

它是.columes的字符串类型,如果删除引号,它将无效。

最新更新