読者です 読者をやめる 読者になる 読者になる

Remrinのpython攻略日記

python3に入門しました。python3についてあれこれとサンプルコードとか。

テストデータ(7) 東京の年平均気温

東京の平均気温(気象庁のサイトより)

# coding: utf-8

import pandas as pd

url = 'http://python-remrin.hatenadiary.jp/entry/2017/05/18/142423'
## DataFrameのリストを得る。header=0のオプション指定で、最初の行をheader扱い。
fetched = pd.io.html.read_html(url)
print(len(fetched))  # listの要素であるDataFrameの個数
df = fetched[0]

# 2次元リスト化
data = []
for i in range(len(df)):
    x = []
    for j in range(len(df.iloc[0])):
        x.append(df.iloc[i, j])
    data.append(x)
print(data)

# hatena表組み化
for i in range(len(df)):
    s = "|"
    for j in range(len(df.iloc[0])):
        s += str(df.iloc[i, j]) + "|"
    print(s)

 

1月 2月 3月 4月 5月 6月 7月 8月 9月 10月 11月 12月 年平均気温
1876 1.6 3.4 ) 8.1 12.2 17.0 18.5 24.3 26.6 22.6 ) 14.8 ) 9.1 4.8 13.6
1877 3.2 3.6 6.2 13.6 16.5 22.0 26.5 25.9 21.3 15.9 9.6 5.8 14.2
1878 2.3 2.5 7.2 11.5 18.3 20.0 26.0 24.6 22.8 15.8 9.7 5.1 13.8
1879 3.2 5.4 8.0 12.6 18.0 21.4 ) 26.1 26.6 21.3 15.0 9.7 8.0 14.6
1880 2.6 5.8 8.4 12.3 17.7 19.8 24.2 25.5 22.5 16.6 10.2 3.9 14.1
1881 2.1 3.7 5.3 11.6 17.2 21.3 24.0 26.7 22.7 15.7 11.0 4.3 13.8
1882 4.6 5.2 6.9 13.7 16.8 20.4 24.2 ) 24.7 ) 21.1 15.4 9.6 5.0 14.0
1883 3.1 1.9 5.3 12.0 15.5 19.8 23.7 25.1 21.8 16.7 10.0 5.0 13.3
1884 2.6 2.7 6.1 11.6 15.5 19.8 23.4 24.1 22.3 15.8 7.6 3.4 12.9
1885 0.6 2.2 ) 4.9 10.7 15.2 20.3 23.1 25.4 22.1 16.1 10.7 5.7 13.1
1886 2.4 2.0 6.9 12.3 16.4 20.9 25.0 26.5 23.2 16.6 10.2 4.7 13.9
1887 2.7 4.3 6.9 12.2 15.2 20.3 23.6 25.3 21.0 16.6 11.6 5.7 13.8
1888 3.3 2.2 7.2 12.4 16.0 18.6 24.5 25.6 20.9 15.0 11.4 5.2 13.5
1889 2.1 3.1 6.9 12.0 15.7 20.9 23.4 25.8 20.3 14.6 9.7 4.9 13.3
1890 3.4 6.1 9.2 14.2 16.1 22.0 23.5 25.4 24.2 16.0 10.8 9.3 15.0
1891 2.4 3.8 8.9 12.0 18.2 20.3 24.9 25.5 24.3 16.5 10.4 5.6 14.4
1892 3.7 4.1 5.1 13.1 16.6 21.1 25.7 26.4 23.0 16.5 9.9 3.3 14.0
1893 2.6 2.2 6.2 13.3 15.8 20.5 25.3 26.2 22.5 15.9 10.1 4.7 13.8
1894 3.0 3.7 8.4 13.8 16.3 23.6 26.8 27.0 21.9 15.4 11.6 5.8 14.8
1895 2.1 4.0 6.9 12.9 17.5 20.4 22.1 25.5 22.9 16.5 9.9 5.4 13.8
1896 3.3 3.5 6.0 13.7 16.6 21.6 24.1 25.9 22.3 15.8 10.7 4.8 14.0
1897 3.7 3.5 5.7 11.3 17.3 18.8 22.9 25.0 20.9 15.2 10.1 3.7 13.2
1898 3.6 4.4 5.5 11.2 16.7 19.2 25.9 26.1 21.6 16.0 10.9 6.4 14.0
1899 3.2 4.2 8.5 12.8 17.9 21.5 23.2 26.1 19.8 14.3 8.9 5.5 13.8
1900 1.6 3.1 5.7 11.4 17.3 19.3 22.8 26.1 22.6 16.5 11.0 5.5 13.6
1901 4.1 3.7 7.3 13.4 16.1 20.6 22.1 25.1 22.3 16.8 10.2 4.5 13.9
1902 2.4 3.8 8.4 11.6 16.3 19.8 21.8 22.9 22.6 16.6 11.5 7.1 13.7
1903 4.6 4.1 7.7 12.7 15.9 19.7 23.2 25.7 22.3 15.2 9.1 4.1 13.7
1904 1.9 4.3 6.1 13.2 15.7 21.8 24.8 25.1 21.2 16.4 9.1 5.3 13.7
1905 4.3 2.7 5.6 10.9 16.9 20.8 23.3 22.2 21.9 16.2 10.3 6.8 13.5
1906 2.2 2.6 7.3 12.9 16.3 18.4 23.5 24.5 19.7 15.1 9.3 5.9 13.1
1907 4.0 2.9 5.6 12.4 17.1 19.2 22.7 25.8 21.3 15.2 11.2 4.5 13.5
1908 3.2 3.4 6.2 12.3 16.1 20.9 22.1 25.4 19.4 16.1 9.1 4.6 13.2
1909 2.1 3.1 6.3 13.6 16.9 20.2 24.3 25.2 21.8 14.8 10.0 4.6 13.6
1910 4.2 2.9 6.1 12.3 16.8 20.7 23.0 24.1 20.9 16.1 10.4 4.3 13.5
1911 2.5 5.2 8.2 13.8 16.2 20.8 24.5 25.6 22.6 15.8 12.8 5.0 14.4
1912 3.0 6.2 8.1 13.0 16.7 20.1 24.3 25.2 20.2 15.9 9.4 4.7 13.9
1913 1.9 4.5 6.2 13.6 16.1 20.3 23.3 23.8 20.0 15.6 10.0 5.2 13.4
1914 4.3 3.5 8.8 11.8 17.8 21.5 25.5 26.4 22.5 16.1 11.9 5.8 14.7
1915 3.3 4.1 6.6 11.6 15.9 21.9 24.2 25.7 22.7 17.6 11.1 5.6 14.2
1916 5.1 4.1 5.8 12.7 16.9 22.7 23.9 25.0 23.7 15.8 11.3 6.8 14.5
1917 2.3 4.5 6.5 12.7 15.8 19.6 25.7 25.0 22.0 16.8 8.7 4.0 13.6
1918 1.6 3.6 6.7 11.7 16.7 20.1 26.0 26.1 22.6 16.0 10.4 3.9 13.8
1919 2.8 3.7 8.3 13.4 16.2 19.8 23.6 25.0 22.7 16.4 11.4 5.3 14.1
1920 4.1 2.6 6.6 12.6 16.8 20.3 26.1 25.7 21.4 16.4 12.0 5.2 14.2
1921 4.0 3.5 6.2 13.8 16.4 18.8 24.3 25.3 21.3 15.4 9.3 5.0 13.6
1922 0.6 7.0 6.6 13.3 16.8 21.7 25.0 27.3 23.4 16.8 10.8 4.0 14.4
1923 1.7 3.0 7.9 12.0 16.8 20.4 24.0 27.2 23.4 ) 16.8 12.0 5.6 14.2
1924 2.7 4.5 5.0 14.7 16.9 19.4 26.1 26.2 21.8 15.4 9.9 5.2 14.0
1925 2.9 2.4 6.2 11.9 16.1 20.1 23.2 25.7 22.9 16.3 11.4 6.8 13.8
1926 3.1 4.6 6.3 11.1 16.3 19.0 24.6 26.3 23.2 15.0 9.8 4.1 13.6
1927 2.7 2.1 6.3 13.5 17.1 20.5 26.0 26.6 21.2 16.7 11.2 5.5 14.1
1928 3.6 3.3 6.9 12.5 17.8 20.3 23.4 24.1 23.9 16.7 11.7 5.4 14.1
1929 2.6 2.9 7.1 12.6 15.9 20.6 25.9 27.1 20.5 16.5 11.0 8.6 14.3
1930 3.8 5.4 8.8 14.0 17.7 21.4 26.3 26.8 21.5 16.7 10.3 5.2 14.8
1931 2.9 2.5 7.9 12.4 16.3 20.4 21.8 26.4 22.5 16.3 11.5 6.9 14.0
1932 5.9 4.3 6.9 12.3 18.0 19.8 25.7 26.7 21.8 16.5 10.9 6.0 14.6
1933 3.2 3.6 5.8 12.3 18.1 21.9 26.6 27.5 23.1 16.8 11.2 6.2 14.7
1934 2.5 4.0 6.1 11.5 17.8 22.0 23.9 26.1 21.6 14.6 10.8 5.9 13.9
1935 3.7 4.8 7.1 12.5 16.7 21.5 24.3 24.8 20.8 17.1 10.7 5.5 14.1
1936 2.0 2.5 6.1 12.0 16.4 21.4 24.9 26.5 24.2 16.0 11.2 6.2 14.1
1937 4.6 5.7 8.1 12.8 17.6 19.6 26.3 28.2 22.7 16.3 11.2 5.2 14.9
1938 2.7 3.4 8.8 13.2 18.7 20.8 25.0 26.0 22.4 16.7 10.8 5.9 14.5
1939 2.4 4.1 7.4 12.8 17.0 20.7 26.5 25.8 23.7 17.9 12.3 5.4 14.7
1940 2.7 3.7 8.2 13.1 17.7 22.1 26.9 24.9 21.7 17.8 12.3 6.2 14.8
1941 4.8 5.0 8.2 12.7 17.6 20.8 23.7 25.4 20.6 17.3 11.7 6.9 14.6
1942 2.9 2.6 10.3 13.6 17.3 22.2 27.5 27.0 24.9 16.4 10.1 5.4 15.0
1943 2.4 4.0 6.8 11.8 17.8 21.5 25.1 27.4 24.4 17.2 10.8 5.7 14.6
1944 3.0 3.2 5.6 10.6 17.7 22.3 25.6 27.5 23.2 16.3 10.9 4.3 14.2
1945 1.1 1.6 6.6 13.5 15.6 20.4 22.0 26.7 22.4 16.8 11.3 4.8 13.6
1946 3.5 4.2 6.2 14.3 16.9 23.3 26.2 26.7 23.1 17.3 12.4 4.7 14.9
1947 3.4 2.7 6.8 13.1 16.9 19.2 25.7 28.0 22.9 15.6 10.3 4.1 14.1
1948 4.0 5.1 6.5 14.2 18.1 21.6 26.0 25.4 23.8 17.4 11.9 7.9 15.2
1949 5.4 6.5 6.7 12.1 18.4 19.4 25.3 26.6 22.4 16.1 10.0 6.0 14.6
1950 5.0 4.7 7.7 13.9 19.2 21.8 26.5 26.2 23.8 15.8 11.1 5.4 15.1
1951 3.3 4.5 8.8 13.3 18.0 21.2 24.3 26.7 20.7 17.3 11.4 7.3 14.7
1952 4.3 2.6 7.4 13.3 18.1 21.3 24.3 26.8 22.7 17.3 12.0 5.3 14.6
1953 3.3 4.2 9.4 12.7 17.8 20.6 24.7 25.0 22.2 17.2 10.4 7.6 14.6
1954 4.3 5.6 8.4 14.9 17.6 18.3 22.3 27.0 24.6 15.5 11.7 7.1 14.8
1955 3.8 6.2 8.7 13.6 18.2 22.7 27.6 26.3 22.3 17.6 11.0 7.9 15.5
1956 4.2 4.3 8.6 13.1 17.6 22.3 24.2 25.4 22.7 17.3 11.8 5.0 14.7
1957 5.7 4.3 6.8 14.3 17.1 19.8 24.4 27.3 20.8 17.2 12.9 8.0 14.9
1958 5.0 6.0 8.4 13.9 18.0 22.0 24.9 25.8 23.2 16.0 11.1 7.9 15.2
1959 3.7 7.3 8.9 15.3 18.5 20.4 26.1 26.7 24.1 17.6 12.3 7.0 15.7
1960 5.0 6.6 9.5 12.8 17.8 21.5 25.8 26.4 23.6 16.8 12.3 6.7 15.4
1961 3.6 4.5 8.2 14.9 19.8 22.6 27.4 26.8 25.3 18.3 12.7 7.2 15.9
1962 4.5 5.9 8.2 14.1 18.4 20.9 25.1 28.1 24.5 16.7 11.3 7.0 15.4
1963 3.2 4.8 7.6 13.9 18.4 21.8 25.7 26.6 21.4 16.3 12.1 8.1 15.0
1964 5.4 4.2 7.6 15.3 18.9 21.5 25.5 27.8 22.3 15.9 11.1 7.5 15.3
1965 4.4 4.7 6.9 11.1 17.2 21.6 24.2 26.7 22.2 16.9 12.7 7.0 14.6
1966 4.6 7.2 9.6 13.6 17.9 20.1 24.4 26.9 23.2 18.9 12.9 6.6 15.5
1967 4.4 4.9 9.5 14.5 20.0 23.0 26.3 28.0 22.6 16.9 12.1 6.7 15.7
1968 5.7 4.3 10.0 14.1 17.5 22.0 24.7 26.6 21.9 16.3 14.1 10.2 15.6
1969 5.7 5.7 7.9 14.6 19.6 21.8 25.0 27.2 22.8 17.3 12.8 7.2 15.6
1970 4.5 6.0 5.5 13.0 19.6 20.7 25.4 27.4 24.0 17.2 12.3 6.8 15.2
1971 5.1 5.9 8.3 13.5 17.4 21.3 25.8 26.7 21.1 15.5 11.9 7.9 15.0
1972 6.6 5.1 9.7 13.4 18.6 21.4 25.2 26.6 23.1 18.5 12.3 8.1 15.7
1973 6.3 6.9 7.8 15.3 17.9 19.8 26.1 28.5 23.2 17.4 12.1 6.6 15.7
1974 4.4 5.1 7.3 14.8 19.3 21.9 23.4 27.1 22.8 17.8 11.7 6.7 15.2
1975 4.7 5.1 7.9 14.3 18.6 21.6 25.6 27.3 25.2 17.3 12.7 6.7 15.6
1976 5.4 6.8 9.0 13.0 17.7 21.5 23.9 25.1 22.0 17.5 11.2 7.3 15.0
1977 3.4 4.9 9.3 15.1 18.7 20.9 25.8 25.0 24.3 18.7 14.8 8.9 15.8
1978 5.6 4.2 8.7 13.9 19.0 23.8 27.8 28.9 22.2 17.3 12.9 8.5 16.1
1979 6.6 8.4 9.9 13.9 18.6 24.4 25.2 27.4 24.1 19.6 14.3 10.1 16.9
1980 5.6 5.2 8.2 13.6 19.2 23.6 23.8 23.4 23.0 18.2 13.0 7.7 15.4
1981 4.4 5.3 9.0 13.9 17.5 20.2 26.3 26.2 21.8 17.6 10.4 7.6 15.0
1982 5.8 5.5 9.9 14.0 20.7 21.4 23.1 27.1 22.3 18.0 14.3 9.5 16.0
1983 6.2 6.1 8.6 15.9 19.7 20.5 23.8 27.5 23.1 17.7 12.3 7.1 15.7
1984 3.7 3.0 5.9 11.6 17.2 21.8 26.2 28.6 23.5 17.7 12.2 7.7 14.9
1985 4.1 6.5 7.8 14.2 19.1 20.2 26.3 27.9 23.1 17.9 13.3 7.4 15.7
1986 4.5 4.3 7.8 13.9 17.9 21.1 23.9 26.8 23.7 17.1 12.3 8.5 15.2
1987 5.8 6.8 9.3 14.4 19.3 22.1 27.0 27.3 23.3 18.9 12.8 8.1 16.3
1988 7.7 4.9 8.4 14.3 18.2 22.3 22.4 27.0 22.8 17.5 11.4 8.4 15.4
1989 8.1 7.5 9.6 15.6 17.7 20.7 24.1 27.1 25.2 17.5 14.2 9.2 16.4
1990 5.0 7.8 10.6 14.7 19.2 23.5 25.7 28.6 24.8 19.2 15.1 10.0 17.0
1991 6.3 6.5 9.5 15.4 18.8 23.6 26.7 25.5 23.9 18.1 13.0 9.2 16.4
1992 6.8 6.9 9.7 15.1 17.3 20.6 25.5 27.0 23.3 17.3 13.0 9.4 16.0
1993 6.2 7.7 8.7 13.4 18.1 21.7 22.5 24.8 22.9 17.5 14.1 8.5 15.5
1994 5.5 6.6 8.1 15.8 19.5 22.4 28.3 28.9 24.8 20.2 13.4 9.0 16.9
1995 6.3 6.5 8.9 15.0 19.1 20.4 26.4 29.4 23.7 19.5 12.7 7.7 16.3
1996 6.6 5.4 9.2 12.7 18.1 22.6 26.2 26.0 22.4 18.0 13.2 9.3 15.8
1997 6.8 7.0 10.5 15.2 19.2 22.7 26.6 27.0 22.9 18.7 14.3 9.2 16.7
1998 5.3 7.0 10.1 16.3 20.5 21.5 25.3 27.2 24.4 20.1 13.9 9.0 16.7
1999 6.6 6.7 10.1 15.0 19.9 22.8 25.9 28.5 26.2 19.5 14.2 9.0 17.0
2000 7.6 6.0 9.4 14.5 19.8 22.5 27.7 28.3 25.6 18.8 13.3 8.8 16.9
2001 4.9 6.6 9.8 15.7 19.5 23.1 28.5 26.4 23.2 18.7 13.1 8.4 16.5
2002 7.4 7.9 12.2 16.1 18.4 21.6 28.0 28.0 23.1 19.0 11.6 7.2 16.7
2003 5.5 6.4 8.7 15.1 18.8 23.2 22.8 26.0 24.2 17.8 14.4 9.2 16.0
2004 6.3 8.5 9.8 16.4 19.6 23.7 28.5 27.2 25.1 17.5 15.6 9.9 17.3
2005 6.1 6.2 9.0 15.1 17.7 23.2 25.6 28.1 24.7 19.2 13.3 6.4 16.2
2006 5.1 6.7 9.8 13.6 19.0 22.5 25.6 27.5 23.5 19.5 14.4 9.5 16.4
2007 7.6 8.6 10.8 13.7 19.8 23.2 24.4 29.0 25.2 19.0 13.3 9.0 17.0
2008 5.9 5.5 10.7 14.7 18.5 21.3 27.0 26.8 24.4 19.4 13.1 9.8 16.4
2009 6.8 7.8 10.0 15.7 20.1 22.5 26.3 26.6 23.0 19.0 13.5 9.0 16.7
2010 7.0 6.5 9.1 12.4 19.0 23.6 28.0 29.6 25.1 18.9 13.5 9.9 16.9
2011 5.1 7.0 8.1 14.5 18.5 22.8 27.3 27.5 25.1 19.5 14.9 7.5 16.5
2012 4.8 5.4 8.8 14.5 19.6 21.4 26.4 29.1 26.2 19.4 12.7 7.3 16.3
2013 5.5 6.2 12.1 15.2 19.8 22.9 27.3 29.2 25.2 19.8 13.5 8.3 17.1
2014 6.3 5.9 10.4 15.0 20.3 23.4 26.8 27.7 23.2 19.1 14.2 6.7 16.6
2015 5.8 5.7 10.3 14.5 21.1 22.1 26.2 26.7 22.6 18.4 13.9 9.3 16.4
2016 6.1 7.2 10.1 15.4 20.2 22.4 25.4 27.1 24.4 18.7 11.4 8.9 16.4