Python Forum
convert string into multiple columns in python3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
convert string into multiple columns in python3
#1
Suppose now I have the following string as below:

'DATA B - 22Aug18\nName Occupation Address Marry Teacher Cali Hobby listen music Sex F Sport swim Jack Doctor Texas Hobby Read book Sex M Sport Badminton \nDATA B - 22Aug18 \nName Occupation Address John student Cali Hobby Game Sex F Sport Tennis Susan freelancer NY Hobby Read book Sex M Sport Running'

And I need to get the following result:

Name Occupation Address Hobby Sex Sport
Mary teacher Cali listen music F swim
Jack Doctor Texas Read book M Badminton
John student Cali Game F Game
Susan freelancer NY Read book M Tennis

I can not how to describe this transformation. Anyone can help me? Thank you
Reply
#2
what have you tried so far?
Show your attempt no matter how terrible you think it is.
Reply
#3
It seems that "value per column" rule doesn't always true for your data (e.g. first row: "listen music" (2 words); third row: "Game" (1 word)). You will probably need to define a set of allowed addresses (in advance) to parse such semi-structured data. "Sex" value could be a delimiter (only "F", "M" are allowed).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python3 string slicing Luchano55 4 530 Feb-17-2024, 09:40 AM
Last Post: Pedroski55
  python convert multiple files to multiple lists MCL169 6 1,431 Nov-25-2023, 05:31 AM
Last Post: Iqratech
  splitting file into multiple files by searching for string AlphaInc 2 812 Jul-01-2023, 10:35 PM
Last Post: Pedroski55
  How to check multiple columns value within range SamLiu 2 1,100 Mar-13-2023, 09:32 AM
Last Post: SamLiu
  convert string to float in list jacklee26 6 1,813 Feb-13-2023, 01:14 AM
Last Post: jacklee26
  how to convert tuple value into string mg24 2 2,233 Oct-06-2022, 08:13 AM
Last Post: DeaD_EyE
  How to move multiple columns to initial position SriRajesh 4 1,373 Jul-02-2022, 10:34 AM
Last Post: deanhystad
  Matching multiple parts in string fozz 31 6,056 Jun-13-2022, 09:38 AM
Last Post: fozz
  Convert string to float problem vasik006 8 3,269 Jun-03-2022, 06:41 PM
Last Post: deanhystad
  Convert a string to a function mikepy 8 2,421 May-13-2022, 07:28 PM
Last Post: mikepy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020