Removing decimal from line chart

Question:

my year data when display on a table its a whole number but when I input it into a line chart under the x axis it splits itself in different time of the year. Could anyone help me sort it into just the year itself?

Here’s my current code:

 df.plot( x = "Year", kind="line", figsize = (10,5), legend = True)
 plt.ticklabel_format(style="plain", axis="y")
 plt.xlabel("Year")
 plt.ylabel("Profit")
 plt.title("Yearly Profit")
 plt.show()

enter image description here

Asked By: nevertoolateyet

||

Answers:

I think you need to specify that the column Year is datetime object:

df['Year'] = pd.to_datetime(df['Year'], format='%Y')

Output:
enter image description here

Answered By: Joe
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.