0

I have a list containing strings that I want to separate with a '|'. The problem I am facing is that creating a pandas series only shows the first few observations followed by ... Is there something I can do to avoid that? Thanks

import pandas as pd

names = pd.Series([['james', 'han', 'sam', 'john', 'dan',
                    'greg', 'adam', 'ben', 'johan', 'asesh', 'kofi']])
name_list = names.str.join('|').to_string(index=False)

enter image description here

Taos
  • 23
  • 4
  • Does this answer your question? [Pretty-print an entire Pandas Series / DataFrame](https://stackoverflow.com/questions/19124601/pretty-print-an-entire-pandas-series-dataframe) – Emmanuel Murairi Jun 15 '23 at 04:21

2 Answers2

1

This answer discusses how Pandas automatically truncates long strings, so your names_list isn't printing because it's been truncated. Set the Pandas parameter below to fix this particular issue:

import pandas as pd
pd.options.display.max_colwidth = None

names = pd.Series([['james', 'han', 'sam', 'john', 'dan',
                    'greg', 'adam', 'ben', 'johan', 'asesh', 'kofi']])
name_list = names.str.join('|').to_string(index=False)
print(name_list)

james|han|sam|john|dan|greg|adam|ben|johan|asesh|kofi
astroChance
  • 337
  • 1
  • 10
0

You can use to_dict() or to_list().

Output:

{0: ['james',
  'han',
  'sam',
  'john',
  'dan',
  'greg',
  'adam',
  'ben',
  'johan',
  'asesh',
  'kofi']}

Or

[['james',
  'han',
  'sam',
  'john',
  'dan',
  'greg',
  'adam',
  'ben',
  'johan',
  'asesh',
  'kofi']]
Scott Boston
  • 147,308
  • 15
  • 139
  • 187