![](/img/trans.png)
[英]Python using pandas to convert xlsx to csv file. How to delete index column?
[英]How to remove index column after Converting xlsx to csv using pandas
import pandas as pd
data_xls=pd.read_excel('/users/adam/abc.xlsx',index=False)
data_xls.to_csv('def.csv,encoding='utf-8')
還嘗試了:
data_xls=pd.read_excel('/users/adam/abc.xlsx',index_col=False)
data_xls=pd.read_excel('/users/adam/abc.xlsx',index=None)
data_xls=pd.read_excel('/users/adam/abc.xlsx',index_col=None)
實際輸出:
Name Age
0 Adam 24
1 Steve 25
2 Jhon 23
預期產量:
Name Age
Adam 24
Steve 25
Jhon 23
有沒有辦法在將數據插入到配置單元表中之前刪除索引列?
編寫文件時,如果不想熊貓在csv文件中編寫索引列,則可以使用以下代碼
pd.to_csv('your.csv', index=False)
另外,如果您要在讀取文件時刪除索引,則應該可以通過以下方法進行操作:
df = pd.read_csv('some.csv').drop(['Unnamed 0'],axis=1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.