2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Pythonによる気象・気候データ解析I 1章章末問題

Last updated at Posted at 2024-05-25

Pythonによる気象・気候データ解析I: Pythonの基礎・気候値と偏差・回帰相関分析

注:しばらくAmazonでは品切れなので楽天等で
Pythonによる気象・気候データ解析1 Pythonの基礎・気候値と偏差・回帰相関分析 [ 神山 翼 ]

の章末問題を一つずつ解いていきます。まずは第1章

A

import numpy as np
import numpy as np

A = np.array([[3, 2, 4],
              [4, 2, 5],
              [7, 2, 9]])
print('AA^T=')
print(np.dot(A, A.T))
print('A^TA=')
print(np.dot(A.T, A))
AA^T=
[[ 29  36  61]
 [ 36  45  77]
 [ 61  77 134]]
A^TA=
[[ 74  28  95]
 [ 28  12  36]
 [ 95  36 122]]

B

  • II巻でも使うので、三角波にしてみました
import matplotlib.pyplot as plt

x = np.linspace(-np.pi, np.pi, 100)
c, s = np.cos(x), np.sin(x)

plt.plot(x, c)
plt.plot(x, s)

plt.grid(linestyle='dashed')

plt.legend(['cos', 'sin'])

plt.show()

image.png

C

# c.f. https://xoblos.hatenablog.jp/entry/2024/02/22/050417

# matplotlib用の日本語対応
!pip install japanize_matplotlib > /dev/null
import japanize_matplotlib

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('https://www.e-stat.go.jp/stat-search/file-download?statInfId=000031524010&fileKind=1', encoding='cp932')

# 「全国」を抽出
df_tokyo = df[df['都道府県名'] == '全国']
df_tokyo = df_tokyo.reset_index(drop=True)

# 西暦(年),人口(男),人口(女)を整数型に
df_tokyo['西暦(年)'] = df_tokyo['西暦(年)'].astype(int)
df_tokyo['人口(男)'] = df_tokyo['人口(男)'].astype(int)
df_tokyo['人口(女)'] = df_tokyo['人口(女)'].astype(int)

df_tokyo.head()

plt.plot(df_tokyo['西暦(年)'], df_tokyo['人口(男)'])
plt.plot(df_tokyo['西暦(年)'], df_tokyo['人口(女)'])

plt.legend(['人口(男)', '人口(女)'])

plt.title('人口推移')
plt.xlabel('西暦(年)')
plt.ylabel('人口(男),人口(女)')

plt.show()
  • あらためて戦争怖いね

image.png

D

price_kaisen = 640
price_ehomaki = 540
price_nebiki = -30

# c.f. https://qiita.com/chatrate/items/21b5c83ecf9197e64299
from datetime import datetime
from datetime import timedelta

start = datetime.strptime('1979-01-01', '%Y-%m-%d')
end   = datetime.strptime('2021-12-31', '%Y-%m-%d')

def daterange(_start, _end):
    for n in range((_end - _start).days + 1): # 最終日も入れるので +1
        yield _start + timedelta(n)

cost = 0

for d in daterange(start, end):
  if '-02-03' in str(d):
    # 節分
    cost += price_ehomaki + str(d).count('9') * price_nebiki
  
  cost += price_kaisen + str(d).count('9') * price_nebiki

print('合計', cost)
合計 9595390

E

import pandas as pd
import matplotlib.pyplot as plt
import japanize_matplotlib

# https://www.data.jma.go.jp/yoho/typhoon/position_table/table2023.html から「台風位置表(CSV形式)」をダウンロード
df = pd.read_csv('table2023.csv', encoding='cp932')
# 2023年に上陸した7号
df01 = df[df['台風番号'] == 2307]
df01 = df01.reset_index(drop=True)
#display(df01.head())

plt.plot(df01['経度'], df01['緯度']) 
plt.xlabel('経度')
plt.ylabel('緯度')
plt.title('台風7号(2023)')
plt.show()

image.png


2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?