import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
import matplotlib.pylab as plt2
import matplotlib.dates as mdates
plt2.rcParams["figure.figsize"] = (8,2.5)
fig, ax0 = plt.subplots()
ax0.set_xlabel('year_month')
ax0.tick_params(axis='x', labelrotation=45)
ax0.set_ylabel('y')
# ax0.set_ylim(400,1200)
x = np.arange(df['date'].size)
y = df['y']
fit = np.polyfit(x, y, 1 )
fit_fn = np.poly1d(fit)
ax0.plot( df['date'], fit_fn(x), 'r--')
ax0.plot( df['date'], df['y'], color='black' , label='총')
https://stackoverflow.com/questions/37337836/linear-regression-with-pandas-time-series
'언어 꿀Tip > Python 꿀tip!' 카테고리의 다른 글
07_01_53. enumerate 함수 이용한 for 문 (0) | 2021.06.17 |
---|---|
07_01_50. DataFrame의 문자열 칼럼을 분할하여 일부분으로 새로운 칼럼 만들기 (0) | 2021.06.17 |
07_01_48. DB2 연결하여 SQL로 데이터 산출 (0) | 2021.06.14 |
07_01_47. json 파일 불러오기 (0) | 2021.06.09 |
07_01_46. 2x2 형태로 여러 line 중첩해서 그래프 그리기 (0) | 2021.06.08 |