What about pandas series is causing this?
plt.plot(df["Column"].as_matrix())
plt.plot(df["Column"])
df["Column"].plot()
actually has similar artifacts, but isn't quite the same plot.
What about pandas series is causing this?
plt.plot(df["Column"].as_matrix())
plt.plot(df["Column"])
df["Column"].plot()
actually has similar artifacts, but isn't quite the same plot.
Let's say you have the following DataFrame
x = [2,1,3,6,5,6,7]
y = [1,2,5,1,1,6,1]
df = pd.DataFrame({"y" : y }, index=x)
Then calling
plt.plot(df["y"].as_matrix()) is equivalent to plt.plot(y) which plots only the y values against it's own index (starting at 0, incrementing by 1).
In contrast,
plt.plot(df["y"]) is equivalent to plt.plot(x,y) which plots the y values against the index of the dataframe. If those indices are not sorted, the plot will look distorted. (The same is true for the pandas plot command.)
Here is a complete example.
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({"y" : [1,2,5,1,1,6,1] }, index=[2,1,3,6,5,6,7])
plt.plot(df["y"].as_matrix(), lw=3, label='plt.plot(df["y"].as_matrix())')
plt.plot(df["y"], lw=3, label='plt.plot(df["y"])')
df["y"].plot(ax=plt.gca(), linestyle="--", color="k", label='df["y"].plot()')
plt.legend()
plt.show()
The easiest solution to be able to use any of the above methods is to reindex the dataframe
df = df.reset_index()
df = df.reset_index() to newly index the dataframe.