■ DataFrame 클래스의 pivot/plot 메소드를 사용해 장소별 일별 LINE 차트를 그리는 방법을 보여준다.
▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import pandas as pd import matplotlib.pyplot as plt sourceDataFrame = pd.read_csv("air_quality_no2_long.csv", parse_dates = ["date.utc"]) renameDataFrame = sourceDataFrame.rename(columns = {"date.utc" : "datetime"}) pivotDataFrame = renameDataFrame.pivot(index = "datetime", columns = "location", values = "value") datetimeIndexResampler = pivotDataFrame.resample("D") targetDataFrame = datetimeIndexResampler.mean() targetDataFrame.plot(style = "-o", figsize = (10, 5)) plt.show() |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
contourpy==1.3.0 cycler==0.12.1 fonttools==4.54.1 kiwisolver==1.4.7 matplotlib==3.9.2 numpy==2.1.2 packaging==24.1 pandas==2.2.3 pillow==11.0.0 pyparsing==3.2.0 python-dateutil==2.9.0.post0 pytz==2024.2 six==1.16.0 tzdata==2024.2 |
※ pip install pandas matplotlib 명령을 실행했다.