0

I have a dataframe df1 with multiple columns. I need to separate each string in this column by capital letters; looks easy but it's not (for me).

I have tried str.split and regex but not working

df1['Edition Statement]=df1['Edition Statement'].str.split('A', expand=True) df1 

Would like to have string separated by capital letters

3
  • 3
    Possible for you to add sample input and expected output? Commented Jun 21, 2019 at 4:02
  • df['Edition Statement'] = df['Edition Statement'].str.split(r'[A-Z]') Commented Jun 21, 2019 at 4:10
  • it should be something like this: Commented Jun 21, 2019 at 5:09

1 Answer 1

1

Try this one:

df1['Edition Statement'].str.split('[A-Z]', expand=True) 

[A-Z] is the regular expression for one capital letter.

Sign up to request clarification or add additional context in comments.

4 Comments

df1['Edition Statement'].str.split('[A-Z]', expand=True) returns the following error: Can only use .str accessor with string values, which use np.object_ dtype in pandas
str.split and I think regex wont work as I Can only use .str accessor with string values, which use np.object_ dtype in pandas
How bloody can I upload a picture to show the issue?
ٌWhat's the dtype of df1['Edition Statement']?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.