Поиск по блогу

понедельник, 16 марта 2015 г.

5 - Combining dataframes and scraping Canadian weather data

Kопипаст из pandas-cookbook. Исследуем погоду в Канаде, дабы потом определить, процент велосипедистов-маньяков, катающихся в дождь. Из таблицы 2012 года вырезаем март, строим график температуры, потом строим таблицу марта с несколькорми прарматрами (влажность, ветер...). Потом убираем оттуда лишние столбцы (день, месяц..., поскольку есть столбец в формате даты). Строим осредненную (за март) дневную диаграмму температуры по часам... Потом собираем все данные за год concat(data_by_month)

By the end of this chapter, we're going to have downloaded all of Canada's weather data for 2012, and saved it to a CSV. We'll do this by downloading it one month at a time, and then combining all the months together. Here's the temperature every hour for 2012!

In [1]:
%matplotlib inline
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

pd.set_option('display.mpl_style', 'default')
plt.rcParams['figure.figsize'] = (15, 3)
In [2]:
weather_2012_final = pd.read_csv('../data/weather_2012.csv', index_col='Date/Time')
weather_2012_final['Temp (C)'].plot(figsize=(15, 6))
Out[2]:
<matplotlib.axes.AxesSubplot at 0x31fdb50>

5.1 Downloading one month of weather data

When playing with the cycling data, I wanted temperature and precipitation data to find out if people like biking when it's raining. So I went to the site for Canadian historical weather data, and figured out how to get it automatically.

Here we're going to get the data for March 2012, and clean it up

Here's an URL template you can use to get data in Montreal.

In [3]:
url_template = "http://climate.weather.gc.ca/climateData/bulkdata_e.html?format=csv&stationID=5415&Year={year}&Month={month}&timeframe=1&submit=Download+Data"

To get the data for March 2013, we need to format it with month=3, year=2012.

In [4]:
url = url_template.format(month=3, year=2012)
weather_mar2012 = pd.read_csv(url, skiprows=16, index_col='Date/Time', parse_dates=True, encoding='latin1')

This is super great! We can just use the same read_csv function as before, and just give it a URL as a filename. Awesome.

There are 16 rows of metadata at the top of this CSV, but pandas knows CSVs are weird, so there's a skiprows options. We parse the dates again, and set 'Date/Time' to be the index column. Here's the resulting dataframe.

In [5]:
weather_mar2012
Out[5]:
Year Month Day Time Data Quality Temp (°C) Temp Flag Dew Point Temp (°C) Dew Point Temp Flag Rel Hum (%) Rel Hum Flag Wind Dir (10s deg) Wind Dir Flag Wind Spd (km/h) Wind Spd Flag Visibility (km) Visibility Flag Stn Press (kPa) Stn Press Flag Hmdx
Date/Time
2012-03-01 00:00:00 2012 3 1 00:00 -5.5 NaN -9.7 NaN 72 NaN 5 NaN 24 NaN 4.0 NaN 100.97 NaN NaN ...
2012-03-01 01:00:00 2012 3 1 01:00 -5.7 NaN -8.7 NaN 79 NaN 6 NaN 26 NaN 2.4 NaN 100.87 NaN NaN ...
2012-03-01 02:00:00 2012 3 1 02:00 -5.4 NaN -8.3 NaN 80 NaN 5 NaN 28 NaN 4.8 NaN 100.80 NaN NaN ...
2012-03-01 03:00:00 2012 3 1 03:00 -4.7 NaN -7.7 NaN 79 NaN 5 NaN 28 NaN 4.0 NaN 100.69 NaN NaN ...
2012-03-01 04:00:00 2012 3 1 04:00 -5.4 NaN -7.8 NaN 83 NaN 5 NaN 35 NaN 1.6 NaN 100.62 NaN NaN ...
2012-03-01 05:00:00 2012 3 1 05:00 -5.3 NaN -7.9 NaN 82 NaN 4 NaN 33 NaN 2.4 NaN 100.58 NaN NaN ...
2012-03-01 06:00:00 2012 3 1 06:00 -5.2 NaN -7.8 NaN 82 NaN 5 NaN 33 NaN 4.0 NaN 100.57 NaN NaN ...
2012-03-01 07:00:00 2012 3 1 07:00 -4.9 NaN -7.4 NaN 83 NaN 5 NaN 30 NaN 1.6 NaN 100.59 NaN NaN ...
2012-03-01 08:00:00 2012 3 1 08:00 -5.0 NaN -7.5 NaN 83 NaN 5 NaN 32 NaN 1.2 NaN 100.59 NaN NaN ...
2012-03-01 09:00:00 2012 3 1 09:00 -4.9 NaN -7.5 NaN 82 NaN 5 NaN 32 NaN 1.6 NaN 100.60 NaN NaN ...
2012-03-01 10:00:00 2012 3 1 10:00 -4.7 NaN -7.3 NaN 82 NaN 5 NaN 32 NaN 1.2 NaN 100.62 NaN NaN ...
2012-03-01 11:00:00 2012 3 1 11:00 -4.4 NaN -6.8 NaN 83 NaN 5 NaN 28 NaN 1.0 NaN 100.66 NaN NaN ...
2012-03-01 12:00:00 2012 3 1 12:00 -4.3 NaN -6.8 NaN 83 NaN 5 NaN 30 NaN 1.2 NaN 100.66 NaN NaN ...
2012-03-01 13:00:00 2012 3 1 13:00 -4.3 NaN -6.9 NaN 82 NaN 6 NaN 28 NaN 1.2 NaN 100.65 NaN NaN ...
2012-03-01 14:00:00 2012 3 1 14:00 -3.9 NaN -6.6 NaN 81 NaN 6 NaN 28 NaN 1.2 NaN 100.67 NaN NaN ...
2012-03-01 15:00:00 2012 3 1 15:00 -3.3 NaN -6.2 NaN 80 NaN 6 NaN 24 NaN 1.6 NaN 100.71 NaN NaN ...
2012-03-01 16:00:00 2012 3 1 16:00 -2.7 NaN -5.7 NaN 80 NaN 7 NaN 19 NaN 2.4 NaN 100.74 NaN NaN ...
2012-03-01 17:00:00 2012 3 1 17:00 -2.9 NaN -5.9 NaN 80 NaN 5 NaN 20 NaN 4.0 NaN 100.80 NaN NaN ...
2012-03-01 18:00:00 2012 3 1 18:00 -3.0 NaN -6.0 NaN 80 NaN 6 NaN 19 NaN 4.0 NaN 100.87 NaN NaN ...
2012-03-01 19:00:00 2012 3 1 19:00 -3.6 NaN -6.4 NaN 81 NaN 6 NaN 17 NaN 3.2 NaN 100.93 NaN NaN ...
2012-03-01 20:00:00 2012 3 1 20:00 -3.7 NaN -6.4 NaN 81 NaN 6 NaN 20 NaN 4.8 NaN 100.95 NaN NaN ...
2012-03-01 21:00:00 2012 3 1 21:00 -3.9 NaN -6.7 NaN 81 NaN 5 NaN 22 NaN 6.4 NaN 100.98 NaN NaN ...
2012-03-01 22:00:00 2012 3 1 22:00 -4.3 NaN -6.9 NaN 82 NaN 5 NaN 22 NaN 2.4 NaN 101.00 NaN NaN ...
2012-03-01 23:00:00 2012 3 1 23:00 -4.3 NaN -7.1 NaN 81 NaN 5 NaN 22 NaN 4.8 NaN 101.04 NaN NaN ...
2012-03-02 00:00:00 2012 3 2 00:00 -4.8 NaN -7.3 NaN 83 NaN 4 NaN 22 NaN 3.2 NaN 101.04 NaN NaN ...
2012-03-02 01:00:00 2012 3 2 01:00 -5.3 NaN -7.9 NaN 82 NaN 5 NaN 20 NaN 4.8 NaN 101.09 NaN NaN ...
2012-03-02 02:00:00 2012 3 2 02:00 -5.2 NaN -7.8 NaN 82 NaN 4 NaN 19 NaN 6.4 NaN 101.11 NaN NaN ...
2012-03-02 03:00:00 2012 3 2 03:00 -5.5 NaN -7.9 NaN 83 NaN 4 NaN 19 NaN 4.8 NaN 101.15 NaN NaN ...
2012-03-02 04:00:00 2012 3 2 04:00 -5.6 NaN -8.2 NaN 82 NaN 5 NaN 24 NaN 6.4 NaN 101.15 NaN NaN ...
2012-03-02 05:00:00 2012 3 2 05:00 -5.5 NaN -8.3 NaN 81 NaN 4 NaN 19 NaN 12.9 NaN 101.15 NaN NaN ...
2012-03-02 06:00:00 2012 3 2 06:00 -5.6 NaN -8.6 NaN 79 NaN 3 NaN 19 NaN 16.1 NaN 101.14 NaN NaN ...
2012-03-02 07:00:00 2012 3 2 07:00 -5.7 NaN -8.7 NaN 79 NaN 3 NaN 22 NaN 24.1 NaN 101.17 NaN NaN ...
2012-03-02 08:00:00 2012 3 2 08:00 -5.7 NaN -8.8 NaN 79 NaN 3 NaN 17 NaN 24.1 NaN 101.20 NaN NaN ...
2012-03-02 09:00:00 2012 3 2 09:00 -6.1 NaN -8.4 NaN 84 NaN 2 NaN 13 NaN 2.0 NaN 101.19 NaN NaN ...
2012-03-02 10:00:00 2012 3 2 10:00 -5.9 NaN -8.3 NaN 83 NaN 1 NaN 15 NaN 4.0 NaN 101.22 NaN NaN ...
2012-03-02 11:00:00 2012 3 2 11:00 -5.5 NaN -7.5 NaN 86 NaN 2 NaN 15 NaN 2.8 NaN 101.21 NaN NaN ...
2012-03-02 12:00:00 2012 3 2 12:00 -5.2 NaN -7.1 NaN 86 NaN 3 NaN 13 NaN 2.4 NaN 101.18 NaN NaN ...
2012-03-02 13:00:00 2012 3 2 13:00 -4.6 NaN -6.5 NaN 87 NaN 3 NaN 13 NaN 4.8 NaN 101.09 NaN NaN ...
2012-03-02 14:00:00 2012 3 2 14:00 -4.1 NaN -6.1 NaN 86 NaN 3 NaN 15 NaN 8.0 NaN 101.03 NaN NaN ...
2012-03-02 15:00:00 2012 3 2 15:00 -3.3 NaN -5.7 NaN 83 NaN 3 NaN 15 NaN 11.3 NaN 100.98 NaN NaN ...
2012-03-02 16:00:00 2012 3 2 16:00 -2.9 NaN -5.3 NaN 83 NaN 3 NaN 15 NaN 11.3 NaN 100.93 NaN NaN ...
2012-03-02 17:00:00 2012 3 2 17:00 -2.7 NaN -5.1 NaN 84 NaN 2 NaN 15 NaN 12.9 NaN 100.89 NaN NaN ...
2012-03-02 18:00:00 2012 3 2 18:00 -2.4 NaN -4.8 NaN 84 NaN 4 NaN 20 NaN 12.9 NaN 100.81 NaN NaN ...
2012-03-02 19:00:00 2012 3 2 19:00 -1.8 NaN -4.2 NaN 84 NaN 3 NaN 17 NaN 16.1 NaN 100.75 NaN NaN ...
2012-03-02 20:00:00 2012 3 2 20:00 -2.3 NaN -4.7 NaN 84 NaN 3 NaN 15 NaN 16.1 NaN 100.74 NaN NaN ...
2012-03-02 21:00:00 2012 3 2 21:00 -1.4 NaN -4.0 NaN 82 NaN 4 NaN 15 NaN 19.3 NaN 100.62 NaN NaN ...
2012-03-02 22:00:00 2012 3 2 22:00 0.2 NaN -4.2 NaN 72 NaN 11 NaN 13 NaN 25.0 NaN 100.49 NaN NaN ...
2012-03-02 23:00:00 2012 3 2 23:00 0.5 NaN -3.6 NaN 74 NaN 13 NaN 17 NaN 25.0 NaN 100.29 NaN NaN ...
2012-03-03 00:00:00 2012 3 3 00:00 1.0 NaN -3.2 NaN 73 NaN 13 NaN 22 NaN 25.0 NaN 100.12 NaN NaN ...
2012-03-03 01:00:00 2012 3 3 01:00 1.2 NaN -2.8 NaN 75 NaN 12 NaN 19 NaN 25.0 NaN 99.96 NaN NaN ...
2012-03-03 02:00:00 2012 3 3 02:00 -0.6 NaN -2.9 NaN 84 NaN 9 NaN 19 NaN 2.4 NaN 99.75 NaN NaN ...
2012-03-03 03:00:00 2012 3 3 03:00 -0.3 NaN -2.4 NaN 86 NaN 10 NaN 22 NaN 2.8 NaN 99.55 NaN NaN ...
2012-03-03 04:00:00 2012 3 3 04:00 0.3 NaN -1.7 NaN 86 NaN 12 NaN 24 NaN 11.3 NaN 99.40 NaN NaN ...
2012-03-03 05:00:00 2012 3 3 05:00 0.8 NaN -1.5 NaN 85 NaN 13 NaN 41 NaN 19.3 NaN 99.18 NaN NaN ...
2012-03-03 06:00:00 2012 3 3 06:00 1.5 NaN -1.6 NaN 80 NaN 14 NaN 43 NaN 25.0 NaN 99.02 NaN NaN ...
2012-03-03 07:00:00 2012 3 3 07:00 2.0 NaN -1.6 NaN 77 NaN 15 NaN 41 NaN 24.1 NaN 98.89 NaN NaN ...
2012-03-03 08:00:00 2012 3 3 08:00 2.7 NaN -1.5 NaN 74 NaN 15 NaN 32 NaN 24.1 NaN 98.79 NaN NaN ...
2012-03-03 09:00:00 2012 3 3 09:00 3.0 NaN -1.0 NaN 75 NaN 16 NaN 37 NaN 24.1 NaN 98.70 NaN NaN ...
2012-03-03 10:00:00 2012 3 3 10:00 3.7 NaN 0.4 NaN 79 NaN 21 NaN 15 NaN 24.1 NaN 98.86 NaN NaN ...
2012-03-03 11:00:00 2012 3 3 11:00 4.0 NaN -0.7 NaN 71 NaN 23 NaN 32 NaN 24.1 NaN 98.82 NaN NaN ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...

744 rows × 24 columns

Let's plot it!

In [6]:
weather_mar2012[u"Temp (\xc2\xb0C)"].plot(figsize=(15, 5))
Out[6]:
<matplotlib.axes.AxesSubplot at 0x338e050>

Notice how it goes up to 25° C in the middle there? That was a big deal. It was March, and people were wearing shorts outside.

And I was out of town and I missed it. Still sad, humans.

I had to write '\xb0' for that degree character °. Let's fix up the columns. We're going to just print them out, copy, and fix them up by hand.

In [6]:
 
In [7]:
weather_mar2012.columns = [
    u'Year', u'Month', u'Day', u'Time', u'Data Quality', u'Temp (C)', 
    u'Temp Flag', u'Dew Point Temp (C)', u'Dew Point Temp Flag', 
    u'Rel Hum (%)', u'Rel Hum Flag', u'Wind Dir (10s deg)', u'Wind Dir Flag', 
    u'Wind Spd (km/h)', u'Wind Spd Flag', u'Visibility (km)', u'Visibility Flag',
    u'Stn Press (kPa)', u'Stn Press Flag', u'Hmdx', u'Hmdx Flag', u'Wind Chill', 
    u'Wind Chill Flag', u'Weather']

You'll notice in the summary above that there are a few columns which are are either entirely empty or only have a few values in them. Let's get rid of all of those with dropna.

The argument axis=1 to dropna means "drop columns", not rows", and how='any' means "drop the column if any value is null".

This is much better now -- we only have columns with real data.

In [8]:
weather_mar2012 = weather_mar2012.dropna(axis=1, how='any')
weather_mar2012[:5]
Out[8]:
Year Month Day Time Data Quality Temp (C) Dew Point Temp (C) Rel Hum (%) Wind Spd (km/h) Visibility (km) Stn Press (kPa) Weather
Date/Time
2012-03-01 00:00:00 2012 3 1 00:00 -5.5 -9.7 72 24 4.0 100.97 Snow
2012-03-01 01:00:00 2012 3 1 01:00 -5.7 -8.7 79 26 2.4 100.87 Snow
2012-03-01 02:00:00 2012 3 1 02:00 -5.4 -8.3 80 28 4.8 100.80 Snow
2012-03-01 03:00:00 2012 3 1 03:00 -4.7 -7.7 79 28 4.0 100.69 Snow
2012-03-01 04:00:00 2012 3 1 04:00 -5.4 -7.8 83 35 1.6 100.62 Snow

5 rows × 12 columns

The Year/Month/Day/Time columns are redundant, though, and the Data Quality column doesn't look too useful. Let's get rid of those.

The axis=1 argument means "Drop columns", like before. The default for operations like dropna and drop is always to operate on rows.

In [9]:
weather_mar2012 = weather_mar2012.drop(['Year', 'Month', 'Day', 'Time', 'Data Quality'], axis=1)
weather_mar2012[:5]
Out[9]:
Temp (C) Dew Point Temp (C) Rel Hum (%) Wind Spd (km/h) Visibility (km) Stn Press (kPa) Weather
Date/Time
2012-03-01 00:00:00 -5.5 -9.7 72 24 4.0 100.97 Snow
2012-03-01 01:00:00 -5.7 -8.7 79 26 2.4 100.87 Snow
2012-03-01 02:00:00 -5.4 -8.3 80 28 4.8 100.80 Snow
2012-03-01 03:00:00 -4.7 -7.7 79 28 4.0 100.69 Snow
2012-03-01 04:00:00 -5.4 -7.8 83 35 1.6 100.62 Snow

5 rows × 7 columns

Awesome! We now only have the relevant columns, and it's much more manageable.

2.3 Plotting the temperature by hour of day

This one's just for fun -- we've already done this before, using groupby and aggregate! We will learn whether or not it gets colder at night. Well, obviously. But let's do it anyway.

In [10]:
temperatures = weather_mar2012[[u'Temp (C)']]
temperatures['Hour'] = weather_mar2012.index.hour
temperatures.groupby('Hour').aggregate(np.median).plot()
Out[10]:
<matplotlib.axes.AxesSubplot at 0x35b6850>

So it looks like the time with the highest median temperature is 2pm. Neat.

5.3 Getting the whole year of data

Okay, so what if we want the data for the whole year? Ideally the API would just let us download that, but I couldn't figure out a way to do that.

First, let's put our work from above into a function that gets the weather for a given month.

I noticed that there's an irritating bug where when I ask for January, it gives me data for the previous year, so we'll fix that too. [no, really. You can check =)]

In [11]:
def download_weather_month(year, month):
    if month == 1:
        year += 1
    url = url_template.format(year=year, month=month)
    weather_data = pd.read_csv(url, skiprows=16, index_col='Date/Time', parse_dates=True)
    weather_data = weather_data.dropna(axis=1)
    weather_data.columns = [col.replace('\xb0', '') for col in weather_data.columns]
    weather_data = weather_data.drop(['Year', 'Day', 'Month', 'Time', 'Data Quality'], axis=1)
    return weather_data

We can test that this function does the right thing:

In [12]:
download_weather_month(2012, 1)[:5]
Out[12]:
Temp (C) Dew Point Temp (C) Rel Hum (%) Wind Spd (km/h) Visibility (km) Stn Press (kPa) Weather
Date/Time
2012-01-01 00:00:00 -1.8 -3.9 86 4 8.0 101.24 Fog
2012-01-01 01:00:00 -1.8 -3.7 87 4 8.0 101.24 Fog
2012-01-01 02:00:00 -1.8 -3.4 89 7 4.0 101.26 Freezing Drizzle,Fog
2012-01-01 03:00:00 -1.5 -3.2 88 6 4.0 101.27 Freezing Drizzle,Fog
2012-01-01 04:00:00 -1.5 -3.3 88 7 4.8 101.23 Fog

5 rows × 7 columns

Now we can get all the months at once. This will take a little while to run.

In [13]:
data_by_month = [download_weather_month(2012, i) for i in range(1, 13)]

Once we have this, it's easy to concatenate all the dataframes together into one big dataframe using pd.concat. And now we have the whole year's data!

In [14]:
weather_2012 = pd.concat(data_by_month)
weather_2012
Out[14]:
Temp (C) Dew Point Temp (C) Rel Hum (%) Wind Spd (km/h) Visibility (km) Stn Press (kPa) Weather
Date/Time
2012-01-01 00:00:00 -1.8 -3.9 86 4 8.0 101.24 Fog
2012-01-01 01:00:00 -1.8 -3.7 87 4 8.0 101.24 Fog
2012-01-01 02:00:00 -1.8 -3.4 89 7 4.0 101.26 Freezing Drizzle,Fog
2012-01-01 03:00:00 -1.5 -3.2 88 6 4.0 101.27 Freezing Drizzle,Fog
2012-01-01 04:00:00 -1.5 -3.3 88 7 4.8 101.23 Fog
2012-01-01 05:00:00 -1.4 -3.3 87 9 6.4 101.27 Fog
2012-01-01 06:00:00 -1.5 -3.1 89 7 6.4 101.29 Fog
2012-01-01 07:00:00 -1.4 -3.6 85 7 8.0 101.26 Fog
2012-01-01 08:00:00 -1.4 -3.6 85 9 8.0 101.23 Fog
2012-01-01 09:00:00 -1.3 -3.1 88 15 4.0 101.20 Fog
2012-01-01 10:00:00 -1.0 -2.3 91 9 1.2 101.15 Fog
2012-01-01 11:00:00 -0.5 -2.1 89 7 4.0 100.98 Fog
2012-01-01 12:00:00 -0.2 -2.0 88 9 4.8 100.79 Fog
2012-01-01 13:00:00 0.2 -1.7 87 13 4.8 100.58 Fog
2012-01-01 14:00:00 0.8 -1.1 87 20 4.8 100.31 Fog
2012-01-01 15:00:00 1.8 -0.4 85 22 6.4 100.07 Fog
2012-01-01 16:00:00 2.6 -0.2 82 13 12.9 99.93 Mostly Cloudy
2012-01-01 17:00:00 3.0 0.0 81 13 16.1 99.81 Cloudy
2012-01-01 18:00:00 3.8 1.0 82 15 12.9 99.74 Rain
2012-01-01 19:00:00 3.1 1.3 88 15 12.9 99.68 Rain
2012-01-01 20:00:00 3.2 1.3 87 19 25.0 99.50 Cloudy
2012-01-01 21:00:00 4.0 1.7 85 20 25.0 99.39 Cloudy
2012-01-01 22:00:00 4.4 1.9 84 24 19.3 99.32 Rain Showers
2012-01-01 23:00:00 5.3 2.0 79 30 25.0 99.31 Cloudy
2012-01-02 00:00:00 5.2 1.5 77 35 25.0 99.26 Rain Showers
2012-01-02 01:00:00 4.6 0.0 72 39 25.0 99.26 Cloudy
2012-01-02 02:00:00 3.9 -0.9 71 32 25.0 99.26 Mostly Cloudy
2012-01-02 03:00:00 3.7 -1.5 69 33 25.0 99.30 Mostly Cloudy
2012-01-02 04:00:00 2.9 -2.3 69 32 25.0 99.26 Mostly Cloudy
2012-01-02 05:00:00 2.6 -2.3 70 32 25.0 99.21 Mostly Cloudy
2012-01-02 06:00:00 2.3 -2.6 70 26 25.0 99.18 Mostly Cloudy
2012-01-02 07:00:00 2.0 -2.9 70 33 25.0 99.14 Mostly Cloudy
2012-01-02 08:00:00 1.9 -3.3 68 39 24.1 99.14 Mostly Cloudy
2012-01-02 09:00:00 1.8 -3.7 67 44 24.1 99.14 Mostly Cloudy
2012-01-02 10:00:00 1.5 -4.1 66 43 24.1 99.18 Mostly Cloudy
2012-01-02 11:00:00 2.2 -3.5 66 30 24.1 99.19 Mostly Cloudy
2012-01-02 12:00:00 1.7 -6.2 56 48 24.1 99.21 Mainly Clear
2012-01-02 13:00:00 1.1 -6.5 57 37 24.1 99.27 Mostly Cloudy
2012-01-02 14:00:00 1.1 -6.8 56 33 24.1 99.33 Mostly Cloudy
2012-01-02 15:00:00 0.0 -7.0 59 33 24.1 99.41 Mostly Cloudy
2012-01-02 16:00:00 -0.7 -8.7 55 24 24.1 99.50 Mostly Cloudy
2012-01-02 17:00:00 -2.1 -9.5 57 22 25.0 99.66 Snow Showers
2012-01-02 18:00:00 -4.1 -11.4 57 28 25.0 99.86 Mostly Cloudy
2012-01-02 19:00:00 -4.8 -12.1 57 24 25.0 100.00 Mostly Cloudy
2012-01-02 20:00:00 -5.6 -13.4 54 24 25.0 100.07 Snow Showers
2012-01-02 21:00:00 -5.8 -12.8 58 26 25.0 100.15 Snow Showers
2012-01-02 22:00:00 -7.0 -14.7 54 20 25.0 100.26 Cloudy
2012-01-02 23:00:00 -7.4 -14.1 59 17 19.3 100.27 Snow Showers
2012-01-03 00:00:00 -9.0 -16.0 57 28 25.0 100.35 Snow Showers
2012-01-03 01:00:00 -9.7 -17.2 54 20 25.0 100.43 Cloudy
2012-01-03 02:00:00 -10.5 -15.8 65 22 12.9 100.53 Snow Showers
2012-01-03 03:00:00 -11.3 -18.7 54 33 25.0 100.61 Snow Showers
2012-01-03 04:00:00 -12.6 -20.1 53 24 25.0 100.68 Cloudy
2012-01-03 05:00:00 -12.9 -19.1 60 22 25.0 100.76 Snow Showers
2012-01-03 06:00:00 -13.3 -19.3 61 19 25.0 100.85 Snow Showers
2012-01-03 07:00:00 -14.0 -19.5 63 19 25.0 100.95 Snow
2012-01-03 08:00:00 -14.8 -21.3 58 26 24.1 101.07 Mostly Cloudy
2012-01-03 09:00:00 -15.0 -21.9 56 19 24.1 101.20 Mostly Cloudy
2012-01-03 10:00:00 -15.3 -22.2 56 24 24.1 101.29 Cloudy
2012-01-03 11:00:00 -14.9 -22.2 54 22 24.1 101.33 Mostly Cloudy
... ... ... ... ... ... ...

8784 rows × 7 columns

5.4 Saving to a CSV

It's slow and unnecessary to download the data every time, so let's save our dataframe for later use!

In [15]:
weather_2012.to_csv('../data/weather_2012.csv')

And we're done!



Посты чуть ниже также могут вас заинтересовать

Комментариев нет:

Отправить комментарий