Can I draw a regression line and show parameters using scatterplot with a pandas dataframe?

Markus W picture Markus W · Apr 5, 2016 · Viewed 23k times · Source

I would like to produce a Scatterplot from a Pandas dataframe using the following code:

df.plot.scatter(x='one', y='two, title='Scatterplot') 

Is there a Parameter I can send with the Statement, so it plots a Regression line and shows the Parameters of the fit?

something like:

df.plot.scatter(x='one', y='two', title='Scatterplot', Regression_line)

Answer

Pascal dB picture Pascal dB · Apr 5, 2016

I don't think that there's such a paramter for DataFrame.plot(). However, you can easily achieve this using Seaborn. Just pass the pandas dataframe to lmplot (assuming you have seaborn installed):

import seaborn as sns
sns.lmplot(x='one',y='two',data=df,fit_reg=True)