13

I am a complete novice when it comes to Python so this might be badly explained.

I have a pandas dataframe with 2485 entries for years from 1960-2020. I want to know how many entries there are for each year, which I can easily get with the .value_counts() method. My issue is that when I print this, the output only shows me the top 5 and bottom 5 entries, rather than the number for every year. Is there a way to display all the value counts for all the years in the DataFrame?

bad_coder
  • 11,289
  • 20
  • 44
  • 72
xceej
  • 159
  • 1
  • 1
  • 7

2 Answers2

23

Use pd.set_options and set display.max_rows to None:

pd.set_option("display.max_rows", None)

Now you can display all rows of your dataframe.

Davide Fiocco
  • 5,350
  • 5
  • 35
  • 72
Corralien
  • 109,409
  • 8
  • 28
  • 52
5

If suppose the name of dataframe is 'df' then use

counts = df.year.value_counts()
counts.to_csv('name.csv',index=false)

As our terminal can't display entire columns they just display the top and bottom by collapsing the remaining values so try saving in a csv and see the records

venkatesh
  • 162
  • 2
  • 6