Python code perform text to column and new column header name follow previous column content

Question:

Anyone can please help how to write Python code to split one column to multiple column by | then each new column header name follow previous new column content. Your help is much appreciate. Thanks.

enter image description here

I able to split text to column but header name not able auto grab from previous column content.

Asked By: Alex Chu

||

Answers:

You can do this:

original_content= 'A|10.5|B|12'
content = original_content.split('|')

result = zip(content[0::2], content[1::2])
print(list(result))
Answered By: phoenixnitin

Is this what you’re asking:

old= 'A|1|B|2|C|3'
new = old.split('|')
final=new[::2],new[1::2]
print(f"{final[0]}n{final[1]}")
Answered By: Nissan Apollo
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.