Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How replace Unnamed header column with previous
#1
Hi,
I have excel file with merged columns as below:

Category	Group			Sub_valid	
	        Name	Item	Value	 Color	 Status
Group1	    VGT	    Power	0	     VGT	 Power
	        BHA	    Voltage	1	     BHA	 Voltage
Group is merged for Name & Item column, Sub_valid is a merged column for Value, Color, Status.
When I read using:
import pandas as pd
df = pd.read_excel('D:PythonCodes\mergedinput.xlsx',sheetname='Sheet1')
The column above Item is "Unnamed0" & Color column & Status column are "Unnamed1", Unnamed2",

But I want:
Category	Group  Group    Sub_valid  Sub_valid  Sub_valid	
	        Name	Item	Value	   Color	  Status
Group1	    VGT	    Power	0	       VGT	      Power
	        BHA	    Voltage	1	       BHA	      Voltage
I use below code but it needs to do multiple time:

df.rename(columns={'*Unnamed: 1':'nan'}, inplace=True)
but I want to replace if header starts with: Unnamed"
Quote

Top Page

Messages In This Thread
How replace Unnamed header column with previous - by SriMekala - Aug-14-2019, 03:43 PM

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to delete column if entire column values are "nan" Sri 4 611 Apr-13-2019, 12:16 PM
Last Post: Sri
Star Pandas referring to result of a previous row slavok400 1 1,534 Sep-27-2018, 03:03 AM
Last Post: slavok400
  How to extract previous and current rows if their value is equal SriRajesh 5 993 Jun-18-2018, 08:09 PM
Last Post: volcano63

Forum Jump:


Users browsing this thread: 1 Guest(s)