python-3.x - 删除数据框 Pn 中添加的默认列
问题描述
我的 DataFrame 上有这个当前输出:
x_1 x_2 x_3 x_4 x_5 ID
0 159 xyz 883nne2 28h93 xx_lightz 10
1 159 xyz 883nne2 28h93 xx_lightz 10
我一直在研究,找不到创建 df 时默认生成的最左侧列的名称(没有列名)。这个名字是什么,它是如何被丢弃的?
预期结果应该是:
x_1 x_2 x_3 x_4 x_5 ID
159 xyz 883nne2 28h93 xx_lightz 10
159 xyz 883nne2 28h93 xx_lightz 10
解决方案
原因是index
,而不是列,让我们检查一下
df.columns
Out[100]: Index(['x_1', 'x_2', 'x_3', 'x_4', 'x_5', 'ID'], dtype='object')
如果只需要print
print(df.to_string(index=False))
x_1 x_2 x_3 x_4 x_5 ID
159 xyz 883nne2 28h93 xx_lightz 10
159 xyz 883nne2 28h93 xx_lightz 10
推荐阅读
- python - 从特定页面抓取特定 URL
- jupyter-notebook - 无法启动内核 [Errorno 2] Jupyter Notebook
- regex - 正则表达式:计算不同地方的出现次数
- javascript - 动态循环多维数组并展平其中的对象
- javascript - 使用 Office JS Api 从 Word 文档的文本框中提取文本
- aws-amplify - AWS APPSYNC 如何应用 aws_api_key 授权
- javascript - 恢复被覆盖的字符串原型
- python - 可视化 google quickdraw 数据
- javascript - 如何使用 HighCharts 库实现这一点
- android - 将本地 .aar 文件添加到 Titanium SDK 9 Android 模块