Home > Software engineering >  Phyton code perform text to column and new column header name follow previous column content
Phyton code perform text to column and new column header name follow previous column content

Time:12-20

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.

CodePudding user response:

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))

CodePudding user response:

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]}")
  • Related