Reputation: 785
I'm trying to build a line plot with Seaborn in Jupyter Notebook, using the code below:
import pandas as pd
import seaborn as sns
# load csv
df=pd.read_csv('C:/Users/1/Desktop/graphs/seaborn/Data.csv')
# make sure date is in datetime
df['Date'] = pd.to_datetime(df['Date'], format='%m-%d-%y')
# generate graph
g = sns.lineplot(x="Date", y="Data", data=df)
plt.show()
However, the result looks like this:
whereas the desired output is as follows (built in Excel):
What argument am I missing in order to make the plot smoother?
The .csv looks like this:
Date,Data
01-09-97,
01-10-97,
01-11-97,
01-12-97,
01-01-98,
01-02-98,
01-03-98,
01-04-98,
01-05-98,309.5
01-06-98,
...
01-07-14,44726.5
01-08-14,45735.1
01-09-14,47430
01-10-14,49887.7
01-11-14,51799.5
01-12-14,54258.1
01-01-15,52079.1
01-02-15,51110.6
01-03-15,49614.8
01-04-15,49989.2
Upvotes: 2
Views: 2363
Reputation: 12410
Simple mistake, your date format is not %m-%d-%y
, but %d-%m-%y
:
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
# load csv
df=pd.read_csv("test.csv")
# make sure date is in datetime
df['Date'] = pd.to_datetime(df['Date'], format='%d-%m-%y')
# generate graph
g = sns.lineplot(x="Date", y="Data", data=df)
plt.show()
Output:
Upvotes: 2