0

I am having a Dataframe which has unnamed column after the concatenation of various csv file. How can I remove it?

Code -

xls = pd.ExcelFile('amex-listing.xlsx')
exchanges = xls.sheet_names
pd.options.display.width = 10000
final_file = 'listing.xlsx'
listings = []
for exchange in exchanges:
    listing = pd.read_excel('amex-listing.xlsx',sheet_name=exchange, na_values='NaN', index_col=False)
    listing['exchange'] = exchange
    sup_df = pd.DataFrame()
    sup_df = listing.append(sup_df)
    listings.append(sup_df)

listings = pd.concat(listings)
listings = listings.reset_index(drop=True)
print(listings)

Excel data -

enter image description here

Data frame -

enter image description here

What should be the best approach to remove the unnamed Dataframe? Also, how can I name this Dataframe if possible?

R_Dax
  • 706
  • 3
  • 10
  • 25
starlord
  • 135
  • 9
  • I think you changed from talking about an unnamed column that needed removing to an unnamed dataframe that needed removing/renaming... please clarify whether it's the column or the dataframe with which you are having an issue – R_Dax Jul 01 '21 at 13:09
  • 1
    That's the index. When writing the excel file, pass `index=False` to `to_excel` – ifly6 Jul 01 '21 at 13:09
  • 1
    `pd.to_excel(...., index=False)` if I've misunderstood let me know and i'll flag to re-open. – Umar.H Jul 01 '21 at 13:26
  • @R_Dax Its the column. After using concat() function I am getting index unnmaed column with it in the Dataframe. What is the best approach to remove that column. I tried .drop() but it needs name which is not there due to its generation along with other columns while concatenation. – starlord Jul 01 '21 at 13:40
  • Thanks @ifly6. I was able to remove that index. Lol, I was using .drop() xD – starlord Jul 01 '21 at 13:46

0 Answers0