2

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

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
nevertoolateyet
  • 131
  • 1
  • 3
  • 10
  • 1
    Create an axis instance ax, plot your df, and then use `ax.xaxis.set_major_formatter(FormatStrFormatter('%d'))` – Sheldore Oct 04 '18 at 12:38

1 Answers1

1

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

Joe
  • 12,057
  • 5
  • 39
  • 55