1

We have a dataframe DF_00:

CODE FACTORS
00 000049668192,000049083092,000049239900,000049304492,000049200300,000049066092
03 000049089310
08 000049239900,000049196700,000049387200
33 000049150097,000049015792
40 000049768051,000049768051,000049768051,000049768051
42 000049768051,000049768051,000049768051,000049768051
60 000049347300
61 000049089310

We need to obtain DF_01:

CODE FACTORS
00 ['000049668192','000049083092','000049239900','000049304492','000049200300','000049066092']
03 ['000049089310']
08 ['000049239900','000049196700','000049387200']
33 ['000049150097','000049015792']
40 ['000049768051','000049768051','000049768051','000049768051']
42 ['000049768051','000049768051','000049768051','000049768051']
60 ['000049347300']
61 ['000049089310']

What we need to do?

2
  • 1
    df.FACTORS.str.split(',') Commented Aug 22, 2020 at 15:57
  • Hi, thank by your answer. The solution is not valid. Array elements are not enclosed in quotes, as in the output example (df_2) above. Commented Aug 24, 2020 at 15:32

1 Answer 1

1

This should do:

df['FACTORS'] = df['FACTORS'].str.split(',').astype(str)
print(df)

   CODE                                            FACTORS
0     0  ['000049668192', '000049083092', '000049239900...
1     3                                   ['000049089310']
2     8   ['000049239900', '000049196700', '000049387200']
3    33                   ['000049150097', '000049015792']
4    40  ['000049768051', '000049768051', '000049768051...
5    42  ['000049768051', '000049768051', '000049768051...
6    60                                   ['000049347300']
7    61                                   ['000049089310']
Sign up to request clarification or add additional context in comments.

3 Comments

Hi, thank by your answer. The solution is not valid. Array elements are not enclosed in quotes, as in the output example (df_2) above.
Do you want a list of strings or do you want it to print that way? This is already a list of strings. Not sure what you want here?
Check edited answer if you want to explicitly convert it to string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.