0

So I need to shift the column to the left to a particular column.

Given Table

H I J K L
Rishabh Uttar Pradesh Lucknow 602303 Yes
Charlie Tamil Nadu Chennai 963258 No
Bheem Rajasthan Bhavnagar 123456 Yes

Desired Output

H I J K L
Rishabh Uttar Pradesh Lucknow 602303 Yes
Charlie Tamil Nadu Chennai 963258 No
Bheem Rajasthan Bhavnagar 123456 Yes

Using Python how can I get this desired output? As we have to use here pandas library but I'm not able to figure out what to do

  • A better option is to prevent this from happening, how did you generate the dataframe? – mozway Mar 28 '22 at 09:44
  • It looks like you need to Split strings in Column "I" and name a new column you will get after the split... not sure why you want to move Headers of the rest... Does not look a good idea – NoobVB Mar 28 '22 at 09:48
  • So I'm doing an internship and the data was given by the company. @mozway – Rishabh Pagaria Mar 28 '22 at 10:59
  • @NoobVB I need to upload the data to the cloud and then do some ETL. So, in order to upload the data the excel file should have equal number of columns as the header, otherwise it will give error – Rishabh Pagaria Mar 28 '22 at 11:02
  • Usually, such a task is performed using matching Headers of the table... And I made a mistake in my initial comment, you do Not need to split, but combine. Start from creating DataFrame from your raw data (you want to upload)... Something like dftest = pd.read_excel(r'C:\Test\test.xlsx') – NoobVB Mar 28 '22 at 12:18
  • Later combine, - read here https://stackoverflow.com/questions/19377969/combine-two-columns-of-text-in-pandas-dataframe – NoobVB Mar 28 '22 at 12:19
  • @NoobVB Yeah I understood this but the data which I've it is not small it has 18 columns. This means till 4 columns everything is good but after 4th column, every column is shifted by one or 2 columns. SO, in this case, I can't merge it would be too complex. – Rishabh Pagaria Mar 28 '22 at 12:30

0 Answers0