Matt Pauly
Matt Pauly

Reputation: 15

Is there a way to plot all columns that only have a specific value in Python using pyplot and pandas?

I am working on a project for a basic Python course and I'm tasked with creating a couple of graphs using data I choose. I'm trying to graph a count how many movies each streaming service has on its platform but the DataFrame I've converted the data into gives me that information in a way I don't know how to process. I've filtered it down to the columns, which are Netflix Hulu and Prime Video, and from there each movie is given a binary value: 1 if on the service, 2 if not. For example: This is the format. How can I create a graph using pandas and pyplot which graphs the count of movies each streaming service has on it? I know I have to graph the '1's, but I don't know how. A simple bar graph with a count of movies for each service is what I'm looking for (x axis is the service, y axis is the movie count).

Upvotes: 1

Views: 44

Answers (1)

jlb_gouveia
jlb_gouveia

Reputation: 603

import pandas as pd
from matplotlib import pyplot as plt

d = {'Netflix': [1,1,1,1,1], 'Hulu':[0,0,0,0,0], 'Prime': [0,0,0,0,1]}
df = pd.DataFrame(d)

plt.bar(df.columns,df.sum())

enter image description here

Upvotes: 1

Related Questions