Hướng dẫn rank plot python
In the end, here is what I did with help of friends
Counting is an essential task required for most analysis projects. The ability to take counts and visualize them graphically using frequency plots (histograms) enables the analyst to easily recognize patterns and relationships within the data. Good news is this can be accomplished using python with just 1 line of code! import pandas as pd %matplotlib inline df = pd.read_csv('iris-data.csv') #toy dataset df.head()
0 Iris-setosa 1 Iris-setosa 2 Iris-setosa 3 Iris-setosa 4 Iris-setosa Name: class, dtype: object Frequency Plot for Categorical Datadf['class'].value_counts() #generate counts Iris-virginica 50 Iris-setosa 49 Iris-versicolor 45 versicolor 5 Iris-setossa 1 Name: class, dtype: int64 Notice that the df['class'].value_counts().plot() I think a bar graph would be more useful, visually. df['class'].value_counts().plot('bar') df['class'].value_counts().plot('barh') #horizontal bar plot df['class'].value_counts().plot('barh').invert_yaxis() #horizontal bar plot There you have it, a ranked bar plot for categorical data in just 1 line of code using python! Histograms for Numberical DataYou know how to graph categorical data, luckily graphing numerical data is even easier using the df['sepal_length_cm'].hist() #horizontal bar plot df['sepal_length_cm'].hist(bins = 30) #add granularity df['sepal_length_cm'].hist(bins = 30, range=[4, 8]) #add granularity & range df['sepal_length_cm'].hist(bins = 30, range=[4, 8], facecolor='gray') #add granularity & range & color There you have it, a stylized histogram for numerical data using python in 1 compact line of code. |