Python 3 Pandas - 带有额外\n\t\t\t\t\t 的列

标签 python excel python-3.x pandas

我有一个来自 .xls 电子表格的数据框,我打印了 print(df.columns.values) 列,输出包含一个名为:Poll Responses\n\t\t\t\t\t

我查看了 Excel 工作表和单元格列标题,没有额外的空格或制表符。

所以为了从这些列中获取数据,我必须使用 print(df['Poll Responses\n\t\t\t\t\t'])

是这样吗,还是我做错了什么?

最佳答案

使用.str.strip:

df.columns = df.columns.str.strip()

这将从数据框中的列标题中去除空格。

关于Python 3 Pandas - 带有额外\n\t\t\t\t\t 的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45152593/

相关文章:

python - 在 Mac 上安装 Python 3.3

python - 迭代列表的列表,不返回子列表中的所有项目

python - Python 3.6+ 中是否有格式化的字节字符串文字?

python - numpy - 使用 np.random.choice 从矩阵中重复采样

python - 如何通过 unix 时间戳合并时间序列数据帧

Excel使用宏复制粘贴值

python - cython_bbox.so : undefined symbol: _Py_ZeroStruct

powershell - 我的程序在IDLE和PyScripter中运行良好,但在PowerShell和命令行中却无法运行

excel - 工作表名称显然不存在

c# - EPPLUS如何使用find命令查找数据