Linear Regression using Pandas
### Code Sample from Stamford

```
[http://stamfordresearch.com/linear-regression-using-pandas-python/](url) (original code)

[](url)
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

data = pd.DataFrame ({
'length' : [94,74,147,58,86,94,63,86,69,72,128,85,82,86,88,72,74,61,90,89,68,76,114,90,78],
'weight' : [130,51,640,28,80,110,33,90,36,38,366,84,80,83,70,61,54,44,106,84,39,42,197,102,57]
})
 
# create another data frame of log values
data_log = np.log(data)


# ========================
# Model for Original Data
# ========================
 
lm_original = np.polyfit(data.length, data.weight, 1)
polynomial = np.poly1d(lm_original)
y =polynomial(data.length)

lm_original_plot=pd.DataFrame({
    'length': data.length,
    'weight': y
        })

# ========================
# Model for Log Data
# ========================
 
# Get the linear models
lm_log = np.polyfit(data_log.length, data_log.weight, 1)
 
# calculate the y values based on the co-efficients from the model
r_x, r_y = zip(*((i, i*lm_log[0] + lm_log[1]) for i in data_log.length))
 
# Put in to a data frame, to keep is all nice
lm_log_plot = pd.DataFrame({
'length' : r_x,
'weight' : r_y
})


# ========================
# Plot the data
# ========================
fig, axes = plt.subplots(nrows=1, ncols=2)
 
# Plot the original data and model
data.plot(kind='scatter', color='Blue', x='length', y='weight', ax=axes[0],title='Original Values')
lm_original_plot.plot(kind='line', color='Red', x='length', y='weight', ax=axes[0])
 
# Plot the log transformed data and model
data_log.plot(kind='scatter', color='Blue', x='length', y='weight', ax=axes[1], title='Log Values')
lm_log_plot.plot(kind='line', color='Red', x='length', y='weight', ax=axes[1])

plt.show()
```

#### Problem description
Pandas doesn't plot the expected graph as the website mention in it.
the bug is at this line:
data.plot(kind='scatter', color='Blue', x='length', y='weight', ax=axes[0],title='Original Values')
lm_original_plot.plot(kind='line', color='Red', x='length', y='weight', ax=axes[0])
The x-axis data is being flipped when pandas try to plot it.
 


![image](https://cloud.githubusercontent.com/assets/29069095/26596610/ed284bf6-45a1-11e7-8cbe-a45721f2ace3.png)





#### Expected Output
![image](https://cloud.githubusercontent.com/assets/29069095/26596592/e070bec0-45a1-11e7-80a9-3f8486c80e3d.png)



#### Output of ``pd.show_versions()``


<details>
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.0.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 42 Stepping 7, GenuineIntel
byteorder: little
LC_ALL: None
LANG: en
LOCALE: None.None

pandas: 0.20.1
pytest: 3.0.5
pip: 9.0.1
setuptools: 35.0.2
Cython: 0.25.2
numpy: 1.12.1
scipy: 0.19.0
xarray: None
IPython: 6.0.0
sphinx: 1.6.2
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.2.2
numexpr: 2.6.2
feather: None
matplotlib: 2.0.2
openpyxl: 2.4.1
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.2
bs4: 4.5.3
html5lib: 0.999999999
sqlalchemy: 1.1.5
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None

</details>
