python - 删除熊猫数据框上的索引和列
问题描述
我有这个清单:
import pandas as pd
l = [[1,2,3],[4,5,6],[7,8,9]]
New_dataframe = pd.DataFrame(l)
print(New_dataframe)
输出:
0 1 2
0 1 2 3
1 4 5 6
2 7 8 9
我想删除那些索引的行和列。如何实现?DataFrame 我想看看是这样的:
1 2 3
4 5 6
7 8 9
如何删除该索引列和行?
解决方案
如果只想看到值可以转换为2d numpy array
:
print (New_dataframe.values)
[[1 2 3]
[4 5 6]
[7 8 9]]
如果需要DataFrame
,可以通过以下方式查看:
print (New_dataframe.to_csv(index=False, header=None, sep=' '))
1 2 3
4 5 6
7 8 9
print (New_dataframe.to_string(index=False, header=None))
1 2 3
4 5 6
7 8 9
编辑:
要转换为没有索引和标题的 excel,请使用参数index=False
和header=None
:
New_dataframe.to_excel('test.xlsx', index=False, header=None)
推荐阅读
- angular - Google Login in Angular 7
- python - python中的函数和类
- terraform - 覆盖来自 terraform 公共注册表模块的默认值
- laravel - How to make Switching button in Laravel Vuejs
- javascript - How do I use state and the value of an object's keys to dynamically style in React?
- json - 动态解码 JSON 单个对象或对象数组
- reactjs - ReactNative Pull To Refresh for iOS platform
- html - 如何获取不是文档子级的div
- python-3.x - Tensorflow - 来自神经网络的预测通常适用于分类中的全 0
- quartz-scheduler - 如何调度在不同调度程序实例中创建的作业