Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot rename Columns in df
#3
You are right. I found there are blank rows at the beginning of the Excel file, Unnamed 0, Unnamed 1, and so on... that is a problem. I thought I could get rid of the "Unnamed" rows and then rename the Headers.
Apparently, that is a huge problem. I tried the following with no good results:
exlf = pd.read_excel('C:/01/XLS_Files/SHORT.xlsx', keep_default_na=False)
exlf = exlf.dropna(how='all').dropna(axis=1, how='all')
exlf = exlf.loc[:, ~exlf.columns.str.contains('^Unnamed')]
exlf = exlf.drop('Unnamed: 0', axis=1, inplace=True)
exlf = exlf.drop(exlf.filter(regex="Unname"),axis=1, inplace=True)
Some of these also remove headers
I could probably just convert the Excel file to CSV, and work with it as a text file. Remove blank lines, rename the headers, and completely process it as I wanted, I thought I could do it all in Pandas, but even removing blank rows is a problem. What I'm doing wrong?
Thank you.
Reply


Messages In This Thread
Cannot rename Columns in df - by tester_V - Aug-25-2023, 04:59 PM
RE: Cannot rename Columns in df - by deanhystad - Aug-25-2023, 05:16 PM
RE: Cannot rename Columns in df - by tester_V - Aug-25-2023, 06:30 PM
RE: Cannot rename Columns in df - by snippsat - Aug-25-2023, 06:59 PM
RE: Cannot rename Columns in df - by tester_V - Aug-25-2023, 07:38 PM
RE: Cannot rename Columns in df - by snippsat - Aug-25-2023, 08:01 PM
RE: Cannot rename Columns in df - by tester_V - Aug-25-2023, 10:34 PM
RE: Cannot rename Columns in df - by snippsat - Aug-26-2023, 12:28 AM
RE: Cannot rename Columns in df - by deanhystad - Aug-26-2023, 01:16 AM
RE: Cannot rename Columns in df - by tester_V - Aug-26-2023, 03:50 AM
RE: Cannot rename Columns in df - by deanhystad - Aug-26-2023, 10:40 PM
RE: Cannot rename Columns in df - by perfringo - Aug-27-2023, 06:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to rename dataframe columns based on the content in an index? ar_mahdavi 2 2,564 Jun-07-2021, 06:09 AM
Last Post: ricslato

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020