■ merge 함수의 how/on 인자를 사용해 데이터를 조인하는 방법을 보여준다.
▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import pandas as pd airQualityStationDataFrame = pd.read_csv("air_quality_stations.csv" ) airQualityNO2DataFrame = pd.read_csv("air_quality_no2_long.csv" , parse_dates = True)[["date.utc", "location", "parameter", "value"]] AirQualityPM25DataFrame = pd.read_csv("air_quality_pm25_long.csv", parse_dates = True)[["date.utc", "location", "parameter", "value"]] airQualityDataFrame = pd.concat([AirQualityPM25DataFrame, airQualityNO2DataFrame], axis = 0).sort_values("date.utc") targetDataFrame = pd.merge(airQualityDataFrame, airQualityStationDataFrame, how = "left", on = "location") print(targetDataFrame) """ date.utc location parameter value coordinates.latitude coordinates.longitude 0 2019-05-07 01:00:00+00:00 London Westminster no2 23.0 51.49467 -0.13193 1 2019-05-07 01:00:00+00:00 FR04014 no2 25.0 48.83724 2.39390 2 2019-05-07 01:00:00+00:00 FR04014 no2 25.0 48.83722 2.39390 3 2019-05-07 01:00:00+00:00 BETR801 pm25 12.5 51.20966 4.43182 4 2019-05-07 01:00:00+00:00 BETR801 no2 50.5 51.20966 4.43182 ... ... ... ... ... ... ... 4177 2019-06-20 23:00:00+00:00 FR04014 no2 21.8 48.83724 2.39390 4178 2019-06-20 23:00:00+00:00 FR04014 no2 21.8 48.83722 2.39390 4179 2019-06-21 00:00:00+00:00 London Westminster pm25 7.0 51.49467 -0.13193 4180 2019-06-21 00:00:00+00:00 FR04014 no2 20.0 48.83724 2.39390 4181 2019-06-21 00:00:00+00:00 FR04014 no2 20.0 48.83722 2.39390 [4182 rows x 6 columns] """ |
▶ requirements.txt
1 2 3 4 5 6 7 8 |
numpy==2.1.2 pandas==2.2.3 python-dateutil==2.9.0.post0 pytz==2024.2 six==1.16.0 tzdata==2024.2 |
※ pip install pandas 명령을 실행했다.
air_quality_stations.csv
air_quality_no2_long.csv
air_quality_pm25_long.csv