Python using pandas to convert xlsx to csv file. How to delete index column?
As noted in the docs for pandas.DataFrame.to_csv()
, simply pass index=False
as a keyword argument, to exclude row names.
data_xls.to_csv('csvfile.csv', encoding='utf-8', index=False)
Inspired by miradulo and fix a number conversion problem:
import pandas as pd
data_xls = pd.read_excel('excelfile.xlsx', 'Sheet2', dtype=str, index_col=None)
data_xls.to_csv('csvfile.csv', encoding='utf-8', index=False)
Can drop 'Sheet2' if there is one sheet. dtype=str to avoid number conversion.