-3

I have a dataframe that has a column 'release_year" that holds the release years of movies. I need to count how many times "2011" shows up in the column "release_year"

I'm allowed to use pandas, numpy and matplotlib

I couldn't get any of the commands to work in my DF

Joe
  • 1
  • 2
  • None of the other questions explain how to count a specific value in a specific column times it shows up – Joe May 13 '19 at 11:53

1 Answers1

0

Look at the pandas function value_counts()

It will give you the counts of the various values occurring in that column. From there picking up the value of 2011 should be straightforward.

The fastest way though, would be to use sum() from numpy on a subset of the data

#assuming your data is loaded in df

(df.release_year.values == '2011').sum()

# or just use the df way

df[df.release_year == '2011'].shape[0]
razdi
  • 1,288
  • 14
  • 18
  • I read this but I am a total nube and couldn't figure out how to make it work with my DF – Joe May 12 '19 at 23:41
  • I've made an edit, check that out. Upvote/accept if the answer helps – razdi May 13 '19 at 00:05
  • TypeError: invalid type comparison I am getting this error off the bottom code recommended – Joe May 13 '19 at 02:16
  • AttributeError: 'bool' object has no attribute 'sum' --- this error when i try the first code – Joe May 13 '19 at 02:16