'show/print plot of frequency table/ result of value_counts()
Looking through the site I found;
fig, ax = plt.subplots()
data.value_counts().plot(ax=ax, kind='bar')
plt.show()
where data is my series. The code runs but doesn't print/show the plot. Why?
So far I've run the following in a colab notebook.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import seaborn as sns
sns.set()
%matplotlib notebook
# define series
data=pd.Series([15,10,17,11,15,.....,17,15,14,13,16])
data.value_counts()
then the above.
Solution 1:[1]
So I kept searching and turned my series into a dataframe and created a bar chart from that which illustrates the mode. So for other complete utter newbies create a dataframe not a series....
pd.DataFrame([15,10,17,11,.....,15,14,13,16])
df = pd.DataFrame(data, columns = ['GamesAttended'])
df
which printed/showed the column
from plotnine import *
ggplot(data = df) + geom_bar(mapping = aes(x = 'GamesAttended'))
which gave me a lovely bar chart.
So I've not answered my original question which is why the code ran but didn't show/print. And I still haven't managed to turn the frequency table/output of value_count() in to a chart but I managed to create a bar chart showing the mode which is what I was supposed to be doing.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
