Skip to content

Instantly share code, notes, and snippets.

@monmonmon
Created Oct 4, 2018
Embed
What would you like to do?
Team AI のデータハッカソンで Kaggle UFO Sightings に1時間程度で挑戦
#!/usr/bin/env python
# UFO Sightings | Kaggle
# https://www.kaggle.com/NUFORC/ufo-sightings
# NASA/Space Data Hackathon(宇宙デー­(­ タ分析ハッカソン) | Meetup
# https://www.meetup.com/ja-JP/Machine-Learning-Meetup-by-team-ai/events/254436043
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'])
plt.show()
# 月別の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'])
plt.show()
# 国ごと (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)
plt.legend()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment