Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How replace Unnamed header column with previous
#4
The following function should do the trick. This won't win any beauty prize however as I just quickly hacked this together.
def repeat_cols(columns):
    last_non_unnamed = '' if 'unnamed' in columns[0].lower() else columns[0]
    new_columns = []
    new_column = ''
    for column in columns:
        if 'unnamed' in column.lower():
            new_column = last_non_unnamed
        else:
            new_column = column
            last_non_unnamed = new_column
        new_columns.append(new_column)
    return new_columns

df.columns = repeat_cols(df.columns)
Quote

Top Page

Messages In This Thread
RE: How replace Unnamed header column with previous - by boring_accountant - Aug-15-2019, 05:10 PM

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to delete column if entire column values are "nan" Sri 4 535 Apr-13-2019, 12:16 PM
Last Post: Sri
Star Pandas referring to result of a previous row slavok400 1 973 Sep-27-2018, 03:03 AM
Last Post: slavok400

Forum Jump:


Users browsing this thread: 1 Guest(s)