How can I drop or disable the indices in a pandas Data Frame?
I am learning the pandas from the book \"python for data analysis\" and I already know I can use the datafr
I was having a similar issue trying to take a DataFrame from an index-less CSV and write it back to another file.
I came up with the following:
import pandas as pd
import os
def csv_to_df(csv_filepath):
# the read_table method allows you to set an index_col to False, from_csv does not
dataframe_conversion = pd.io.parsers.read_table(csv_filepath, sep='\t', header=0, index_col=False)
return dataframe_conversion
def df_to_excel(df):
from pandas import ExcelWriter
# Get the path and filename w/out extension
file_name = 'foo.xlsx'
# Add the above w/ .xslx
file_path = os.path.join('some/directory/', file_name)
# Write the file out
writer = ExcelWriter(file_path)
# index_label + index are set to `False` so that all the data starts on row
# index 1 and column labels (called headers by pandas) are all on row index 0.
df.to_excel(writer, 'Attributions Detail', index_label=False, index=False, header=True)
writer.save()