NO2
) concentration expressed as parts per million (`ppm`).\n"],"metadata":{"id":"EsEkwMtRcTJx"}},{"cell_type":"code","source":["import pandas as pd, numpy as np # import statements\n","df = pd.read_csv(\"https://raw.githubusercontent.com/kwaldenphd/elements-of-computing/main/book/data/ch7/air_quality_no2.csv\", index_col=0, parse_dates=True)\n","df.info()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"Or3qMl6ecnAA","executionInfo":{"status":"ok","timestamp":1705965183471,"user_tz":300,"elapsed":975,"user":{"displayName":"Katherine Walden","userId":"17094108395123900917"}},"outputId":"900619bc-ecfb-4463-9f59-f93c78035da5"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["NO2
concentration as milligrams per cubic meter (mg/m3). For our purposes, we are assuming a temperature of 25 degrees Celsius and pressure of 1013 hPa, which means the conversion factor is 1.882.\n","\n","\n","\n","We would need to convert all of the `station_london` column values from `ppm` to mg/m3
. And we would want to store the results of that calculation in a newly-created column."],"metadata":{"id":"DuAeQLgccvtN"}},{"cell_type":"code","source":["df['london_mg_per_cubic'] = df['station_london'] * 1.882 # create new column from arithmetic operation\n","df.head() # show output"],"metadata":{"id":"caYbjmPwc1iO"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## Example #2\n","\n","\n","\n","Let's say we wanted to calculate the ratio of the Paris versus Antwerp station values and store that result in a new column. We would need to calculate the ratio for each row and store the results of the calculation in a new column."],"metadata":{"id":"R8DT1P2udKo8"}},{"cell_type":"code","source":["df[\"ratio_paris_antwerp\"] = (df[\"station_paris\"] / df[\"station_antwerp\"]) # calculate ration\n","df.head() # show output"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":344},"id":"CkSV1sERdNuR","executionInfo":{"status":"ok","timestamp":1705965335856,"user_tz":300,"elapsed":137,"user":{"displayName":"Katherine Walden","userId":"17094108395123900917"}},"outputId":"fff74e21-534b-461d-e871-f3fc3c2b6765"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" station_antwerp station_paris station_london \\\n","datetime \n","2019-05-07 02:00:00 NaN NaN 23.0 \n","2019-05-07 03:00:00 50.5 25.0 19.0 \n","2019-05-07 04:00:00 45.0 27.7 19.0 \n","2019-05-07 05:00:00 NaN 50.4 16.0 \n","2019-05-07 06:00:00 NaN 61.9 NaN \n","\n"," ratio_paris_antwerp \n","datetime \n","2019-05-07 02:00:00 NaN \n","2019-05-07 03:00:00 0.495050 \n","2019-05-07 04:00:00 0.615556 \n","2019-05-07 05:00:00 NaN \n","2019-05-07 06:00:00 NaN "],"text/html":["\n"," \n"," | station_antwerp | \n","station_paris | \n","station_london | \n","ratio_paris_antwerp | \n","
---|---|---|---|---|
datetime | \n","\n"," | \n"," | \n"," | \n"," |
2019-05-07 02:00:00 | \n","NaN | \n","NaN | \n","23.0 | \n","NaN | \n","
2019-05-07 03:00:00 | \n","50.5 | \n","25.0 | \n","19.0 | \n","0.495050 | \n","
2019-05-07 04:00:00 | \n","45.0 | \n","27.7 | \n","19.0 | \n","0.615556 | \n","
2019-05-07 05:00:00 | \n","NaN | \n","50.4 | \n","16.0 | \n","NaN | \n","
2019-05-07 06:00:00 | \n","NaN | \n","61.9 | \n","NaN | \n","NaN | \n","