Skip to content

Instantly share code, notes, and snippets.

Created Oct 4, 2018
What would you like to do?
Team AI のデータハッカソンで Kaggle UFO Sightings に1時間程度で挑戦
#!/usr/bin/env python
# UFO Sightings | Kaggle
# NASA/Space Data Hackathon(宇宙デー­(­ タ分析ハッカソン) | Meetup
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
ds = pd.read_csv('scrubbed.csv')
ds['datetime'] = pd.to_datetime(ds['datetime'], errors='coerce')
# 年別のUFO観測件数をグラフにプロット
ds['year'] = ds['datetime'].map(lambda x: x.year)
yy = ds['year'].value_counts().reset_index()
yy = yy.sort_values(by='index')
plt.plot(yy['index'], yy['year'])
# 月別のUFO観測件数をグラフにプロット
ds['month'] = ds['datetime'].map(lambda x: x.month)
mm = ds['month'].value_counts().reset_index()
mm = mm.sort_values(by='index')
plt.plot(mm['index'], mm['month'])
# 国ごと (us, ca, gb, au, de, na) の月別のUFO観測件数をグラフにプロット
from sklearn.preprocessing import StandardScaler
countries = ds['country'].fillna('na').unique()
for country in countries:
cc = ds[ ds['country'] == country ]
cc['month'] = cc['datetime'].map(lambda x: x.month)
hoge = cc['month'].value_counts().reset_index().sort_values(by='index')
plt.plot(hoge['index'], hoge['month'], label=country)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment