0

I m trying to use countplot with release date of movie in x axis where I need to use only the year to plot the graph.Please see the code and the graph below.

sns.countplot(x=pd.DatetimeIndex(movie['release date']).year.drop_duplicates(), data=movie)

The data is not plotted correctly and the years are merged even if i use rotation=45. Please help

enter image description here

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Ananya
  • 13
  • 3

1 Answers1

1

Since there was no data presented, I got the data from this site and responded to it. The date and time data columns are converted to date format by pandas, and the year information is added as a new column based on that. Run countplot on that column.

movies_rating.head()
    user_id     rating  rating_timestamp    movie_title     genres
movie_id                    
8   42514   5   2014-04-08 18:20:11     Edison Kinetoscopic Record of a Sneeze (1894)   Documentary|Short
10  69964   10  2014-10-09 18:15:53     La sortie des usines Lumiティre (1895)    Documentary|Short
12  68927   10  2015-08-10 23:16:19     The Arrival of a Train (1896)   Documentary|Short
25  37289   8   2017-02-27 10:04:59     The Oxford and Cambridge University Boat Race ...   NaN
91  5759    6   2013-11-23 18:59:55     Le manoir du diable (1896)  Short|Horror

movies_rating['rating_timestamp'] = pd.to_datetime(movies_rating['rating_timestamp'])
movies_rating['year'] = movies_rating['rating_timestamp'].dt.year
sns.countplot(x='year', data=movies_rating,)

enter image description here

r-beginners
  • 31,170
  • 3
  • 14
  • 32
  • Thank you. Yes I was able to retrieve year and plot but since I have 71 unique year, the x axis is kind of merged and the bar chart is closely aligned. Is there a way to make the x axis big and to create space between bars. – Ananya Mar 25 '21 at 03:15
  • Since I can't see the results, I don't know how dense it is, but as a countermeasure, 1) increase the width of the graph, and 2) make the graph vertical. In this example, we will fix this.`sns.countplot(y='year', data=movies_rating)` – r-beginners Mar 25 '21 at 03:32