Suppose I have a Pandas dataframe with discrete values in a column.
import pandas as pd
data = ['A']*2 + ['C']*3 + ['B']* 1
print(data)
# ['A', 'A', 'C', 'C', 'C', 'B']
my_df = pd.DataFrame({'mycolumn': data})
print(my_df)
# mycolumn
# 0 A
# 1 A
# 2 C
# 3 C
# 4 C
# 5 B
I then create a histogram showing the frequency of those values. I use the Pandas built-in function hist()
, which in turn relies on the Matplotlib histogram function.
my_df.mycolumn.hist()
Now, how do I change the order of the labels on the X-axis to have a specific order? For example, I want the x-axis to have the labels in the specific order: C, A, B
, not A, C, B
as is shown.
Additionally, how do I change the y-axis to be integers rather than floats? The frequency values are discrete counts.