統計処理 (Statistical Processing)
合計、最大、最小
def calculate_sum(data):
total = 0
for num in data:
total += num
return total
data = [1, 330, 120, 500, 40]
print(calculate_sum(data)) # 出力: 991
平均、中央値
def calculate_average(data):
if data == []:
return None # リストが空の場合の処理
average = calculate_sum(data) / len(data)
return average
data = [1, 330, 120, 500, 40]
print(calculate_average(data)) # 出力: 198.2
def find_median(data):
sorted_data = sorted(data)
n = len(sorted_data)
mid = n // 2
if n % 2 == 0: # 偶数個の場合
median = (sorted_data[mid - 1] + sorted_data[mid]) / 2
else: # 奇数個の場合
median = sorted_data[mid]
return median
data = [1, 330, 120, 500, 40]
print(find_median(data)) # 出力: 120
移動平均
度数
分散、標準偏差、四分位数
def calculate_variance(data):
if len(data) == 0:
return 0 # リストが空の場合の処理
mean = calculate_sum(data) / len(data) # 平均値を計算
# 分散を計算
variance = sum((x - mean) ** 2 for x in data) / len(data)
return variance
data = [1, 330, 120, 500, 40]
print(calculate_variance(data)) # 出力: 36724.16
import math
def calculate_standard_deviation(data):
if len(data) == 0:
return 0 # リストが空の場合の処理
# 分散を計算
variance = calculate_variance(data)
# 標準偏差を計算
standard_deviation = math.sqrt(variance)
return standard_deviation
data = [1, 330, 120, 500, 40]
print(calculate_standard_deviation(data)) # 出力: 191.57
回帰分析
大谷さん 50-50
地球温暖化
- 最近50年の東京の8月の平均気温のpythonリスト
- 大阪は?
- 福岡は?
- 札幌は?
- 仙台のリストは?
- 東京の1月の平均気温のリストは?
- 大阪は?
- 福岡のリストは?
- 札幌は?
二酸化炭素濃度
人口
1950年から2024年までの日本の総人口データをPythonリスト
1950年から2024年までの日本の総人口データを年と人口の対にした辞書型のPythonデータで
japan_population_dict = {
1950: 83493000,
1951: 84701000,
1952: 86002000,
1953: 87296000,
1954: 88592000,
1955: 89883000,
1956: 91179000,
1957: 92471000,
1958: 93759000,
1959: 95040000,
1960: 96317000,
1961: 97590000,
1962: 98859000,
1963: 100124000,
1964: 101385000,
1965: 102643000,
1966: 103891000,
1967: 105127000,
1968: 106352000,
1969: 107564000,
1970: 108764000,
1971: 109951000,
1972: 111126000,
1973: 112288000,
1974: 113438000,
1975: 114576000,
1976: 115702000,
1977: 116815000,
1978: 117916000,
1979: 119005000,
1980: 120082000,
1981: 121146000,
1982: 122198000,
1983: 123238000,
1984: 124266000,
1985: 125281000,
1986: 126284000,
1987: 127275000,
1988: 128254000,
1989: 129221000,
1990: 123611000,
1991: 123921000,
1992: 124229000,
1993: 124536000,
1994: 124961000,
1995: 125439000,
1996: 125757000,
1997: 126057000,
1998: 126400000,
1999: 126631000,
2000: 126843000,
2001: 127149000,
2002: 127445000,
2003: 127718000,
2004: 127761000,
2005: 127773000,
2006: 127854000,
2007: 127771000,
2008: 127704000,
2009: 127503000,
2010: 127176000,
2011: 126995000,
2012: 126659000,
2013: 126393000,
2014: 126010000,
2015: 125570000,
2016: 125020000,
2017: 124270000,
2018: 123420000,
2019: 122510000,
2020: 121440000,
2021: 120410000,
2022: 119220000,
2023: 118000000,
2024: 117000000 # 概算値
}
1950年以降の毎年の日本の出生数と死亡者数を示すPythonリストを省略せずに作成して
japan_population_data = [
{"year": 1950, "births": 2337507, "deaths": 904876},
{"year": 1951, "births": 2137689, "deaths": 838998},
{"year": 1952, "births": 2005162, "deaths": 765068},
{"year": 1953, "births": 1868040, "deaths": 772547},
{"year": 1954, "births": 1769580, "deaths": 721491},
{"year": 1955, "births": 1730692, "deaths": 693523},
{"year": 1956, "births": 1665278, "deaths": 724460},
{"year": 1957, "births": 1566713, "deaths": 752445},
{"year": 1958, "births": 1653469, "deaths": 684189},
{"year": 1959, "births": 1626088, "deaths": 689959},
{"year": 1960, "births": 1606041, "deaths": 706599},
{"year": 1961, "births": 1589372, "deaths": 695644},
{"year": 1962, "births": 1618616, "deaths": 710265},
{"year": 1963, "births": 1659521, "deaths": 670770},
{"year": 1964, "births": 1716761, "deaths": 673067},
{"year": 1965, "births": 1823697, "deaths": 700438},
{"year": 1966, "births": 1360974, "deaths": 670342},
{"year": 1967, "births": 1935647, "deaths": 675006},
{"year": 1968, "births": 1871839, "deaths": 686555},
{"year": 1969, "births": 1889815, "deaths": 693787},
{"year": 1970, "births": 1934239, "deaths": 712962},
{"year": 1971, "births": 2000973, "deaths": 684521},
{"year": 1972, "births": 2038682, "deaths": 683751},
{"year": 1973, "births": 2091983, "deaths": 709416},
{"year": 1974, "births": 2029989, "deaths": 710510},
{"year": 1975, "births": 1901440, "deaths": 702275},
{"year": 1976, "births": 1832617, "deaths": 703270},
{"year": 1977, "births": 1755100, "deaths": 690074},
{"year": 1978, "births": 1708643, "deaths": 695821},
{"year": 1979, "births": 1642580, "deaths": 689664},
{"year": 1980, "births": 1576889, "deaths": 722801},
{"year": 1981, "births": 1529455, "deaths": 720262},
{"year": 1982, "births": 1515392, "deaths": 711883},
{"year": 1983, "births": 1508687, "deaths": 740038},
{"year": 1984, "births": 1489780, "deaths": 740247},
{"year": 1985, "births": 1431577, "deaths": 752283},
{"year": 1986, "births": 1382946, "deaths": 750620},
{"year": 1987, "births": 1346658, "deaths": 751172},
{"year": 1988, "births": 1314006, "deaths": 793014},
{"year": 1989, "births": 1246802, "deaths": 788594},
{"year": 1990, "births": 1221585, "deaths": 820305},
{"year": 1991, "births": 1223245, "deaths": 829797},
{"year": 1992, "births": 1208989, "deaths": 856643},
{"year": 1993, "births": 1188282, "deaths": 878532},
{"year": 1994, "births": 1238328, "deaths": 875933},
{"year": 1995, "births": 1187064, "deaths": 922139},
{"year": 1996, "births": 1206555, "deaths": 896211},
{"year": 1997, "births": 1191665, "deaths": 913402},
{"year": 1998, "births": 1203147, "deaths": 936484},
{"year": 1999, "births": 1177669, "deaths": 982031},
{"year": 2000, "births": 1190547, "deaths": 961653},
{"year": 2001, "births": 1170662, "deaths": 970331},
{"year": 2002, "births": 1153855, "deaths": 982379},
{"year": 2003, "births": 1123610, "deaths": 1014951},
{"year": 2004, "births": 1110721, "deaths": 1028602},
{"year": 2005, "births": 1062530, "deaths": 1083796},
{"year": 2006, "births": 1092674, "deaths": 1084450},
{"year": 2007, "births": 1089818, "deaths": 1108334},
{"year": 2008, "births": 1091156, "deaths": 1142407},
{"year": 2009, "births": 1070035, "deaths": 1141865},
{"year": 2010, "births": 1071304, "deaths": 1197012},
{"year": 2011, "births": 1050806, "deaths": 1253066},
{"year": 2012, "births": 1037315, "deaths": 1265120},
{"year": 2013, "births": 1029825, "deaths": 1279380},
{"year": 2014, "births": 1003532, "deaths": 1292660},
{"year": 2015, "births": 1005677, "deaths": 1305670},
{"year": 2016, "births": 976979, "deaths": 1307440},
{"year": 2017, "births": 946060, "deaths": 1343055},
{"year": 2018, "births": 918397, "deaths": 1362480},
{"year": 2019, "births": 865239, "deaths": 1381093},
{"year": 2020, "births": 840835, "deaths": 1377644},
{"year": 2021, "births": 811604, "deaths": 1431000},
{"year": 2022, "births": 771801, "deaths": 1465000},
{"year": 2023, "births": 729367, "deaths": 1480000},
{"year": 2024, "births": 700000, "deaths": 1500000} # 2024年のデータは仮の値です
]
1966年丙午、ひのえうま