0

I have a pandas data frame with a column that has a lot of categories within it. I need to create a list containing the name of each category within that column. I can create the list, but because the column has 287 categories, python will only print an abbreviated version of the list. How do I get python to return/print the full list?

y = season_data['Period Name'].value_counts()
period_name_list = (y.index)
print(period_name_list)

This is what I get when I input the print() function.

Index(['Special Teams', 'Session', 'Team 1', 'Team 4', 'Team 3', 'Team 2', 'Team 6', 'Team 5', 'Flex', 'Indy',
...
'SPECIAL TEAM 1', 'Q3 P 4', 'Q3 OD 10', 'Q3 PR 7', 'Quarter 26','Q3 OD 11', 'TEAMS 2', 'Q3 DD 12', 'Special teams 3', 'Q3 DD 13'],
dtype='object', length=287)

How do I print the full list? I am using jupyter Notebook, also if I could display the output as an HTML file to open in browser that would help to.

smci
  • 32,567
  • 20
  • 113
  • 146
Mark Mamon
  • 45
  • 4
  • this will help https://stackoverflow.com/questions/11707586/how-do-i-expand-the-output-display-to-see-more-columns-of-a-pandas-dataframe – deadshot Jul 24 '21 at 20:59
  • 1
    That's not base Python, it's pandas. pandas is introducing the `...` ellipsis when the Series has more than threshold items. You can change that with `pd.options.display...` – smci Jul 24 '21 at 21:01
  • `print(list(period_name_list))` – Henrik Bo Jul 24 '21 at 21:03
  • `pd.options.display.max_rows = 287` – smci Jul 24 '21 at 21:05

1 Answers1

0

Use tolist method:

>>> idx
Index(['', 'Lorem', 'ipsum', 'dolor', 'sit', 'amet,', 'consectetur',
       'adipiscing', 'elit.', 'Etiam',
       ...
       'erat', 'augue,', 'consequat', 'nec', 'viverra', 'non,', 'cursus',
       'sit', 'amet', 'nibh.'],
      dtype='object', length=469)
>>> idx.tolist()
['',
 'Lorem',
 'ipsum',
 'dolor',
 'sit',
 'amet,',
 'consectetur',
 'adipiscing',
 'elit.',
 'Etiam',
 'mi',
 'est,',
 'dignissim',
 'sit',
 'amet',
 'mollis',
 'vel,',
 'porta',
 'in',
 'eros.',
 'Quisque',
 'est',
 'purus,',
 'auctor',
 'ut',
 'tincidunt',
 'ut,',
 'pretium',
 'sed',
 'ex.',
 'Vivamus',
 'vel',
 'molestie',
 'arcu.',
 'Morbi',
 'orci',
 'nunc,',
 'posuere',
 'quis',
 'leo',
 'imperdiet,',
 'porta',
 'suscipit',
 'nisl.',
 'Ut',
 'ultricies',
 'quis',
 'augue',
 'at',
 'tempus.',
# Too long
Corralien
  • 109,409
  • 8
  • 28
  • 52