0

I have a bunch of strings stored in a field called bio in a df called df_info. Some of them have multiple lines in their strings as such:

Journalist and Reporter 
Baltimore Girl Living In A Nashville World 
Surviving Off Of Target Pick Up, Coffee & My Fave Playlists ☕️  #Debtfreeliving

Others are already one line like such:

Professional basketball blogger and dog mom

I am trying to get all of the fields in bio to be one readable text line so that the first example looks like this:

Journalist and Reporter  Baltimore Girl Living In A Nashville World Surviving Off Of Target Pick Up, Coffee & My Fave Playlists ☕️  #Debtfreeliving

I've tried using previous answers to similar questions like this:

df_info.bio = str.join(" ", df_info.bio.splitlines())

But it tells me: AttributeError: 'Series' object has no attribute 'splitlines'

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
wizkids121
  • 634
  • 1
  • 9
  • 22
  • 1
    Are you using `pandas`? A `Series` is not a standard python object type. – BeRT2me Sep 27 '22 at 15:58
  • Yeah I believe I'm using `pandas` – wizkids121 Sep 27 '22 at 16:02
  • are you looking for `pd.Series.str.split("\n")`? [How to split a python dataframe based on new line characters?](https://stackoverflow.com/q/68520893/10197418) – FObersteiner Sep 27 '22 at 16:02
  • @FObersteiner - Maybe? What would that look like in the context of my script? – wizkids121 Sep 27 '22 at 16:04
  • 1
    something like `df_info.bio = df_info.bio.str.split("\n").str.join(" ")` to split on newline, then join with a space. So basically you're looking for the `str` accessor. – FObersteiner Sep 27 '22 at 16:06
  • You can see [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) for how you can improve this question, and future pandas related questions~ – BeRT2me Sep 27 '22 at 16:12

0 Answers0