This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add(a, b): | |
return a + b | |
# see: https://peps.python.org/pep-0008/#programming-recommendations | |
add_lambda = lambda a, b: a + b | |
if __name__ == '__main__': | |
print(add(1, 2)) | |
print(add_lambda(1, 2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import python_const_0 as Pt | |
Pt.MAX_TIME = 10 | |
Pt.METHOD = "GET" | |
def main(): | |
print(Pt.MAX_TIME) | |
print(Pt.METHOD) | |
# 代入できない |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MAX_TIME = 10 | |
def main(): | |
# グローバル変数 | |
global MAX_TIME | |
print(MAX_TIME) | |
# 書き換えられてしまう | |
MAX_TIME = 20 | |
print(MAX_TIME) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
print(math.pi) | |
# 上書き | |
math.pi = 10 | |
print(math.pi) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Constant types in Python. | |
e.g., http://code.activestate.com/recipes/414140-constant-types-in-python/ | |
""" | |
import sys | |
class _const: | |
class ConstError(TypeError): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
# 都道府県名をindexとして読み込む | |
# [m]単位の人口を追加する | |
df = pd.read_csv("data.csv", index_col=0) | |
series_pop_million = df["population"].map(lambda x: x / 100) | |
series_pop_million.name = "population[m]" | |
df = pd.concat([df, series_pop_million], axis=1) | |
# 面積 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
# 都道府県名をindexとして読み込む | |
# [m]単位の人口を追加する | |
df = pd.read_csv("data.csv", index_col=0) | |
series_pop_million = df["population"].map(lambda x: x / 100) | |
series_pop_million.name = "population[m]" | |
df = pd.concat([df, series_pop_million], axis=1) | |
# 北海道 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from pandas_profiling import ProfileReport | |
# データを読み込む | |
df = pd.read_csv("data.tsv", index_col=0, delimiter="\t", | |
names=["setai", "p", "pm", "pf"]) | |
# レポートを作成する | |
profile = ProfileReport(df, title="23 Wards of Tokyo") | |
profile.to_file(output_file="profile.html") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
import os.path | |
# sub かつ txt | |
print("[1]") | |
for filename in glob.glob("working/**/sub*/**", recursive=True): | |
if filename.endswith(".txt"): | |
print(filename) | |
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
# * の場合 | |
print(glob.glob("working/*")) | |
print(glob.glob("working/*", recursive=True)) | |
# ** の場合 | |
print(glob.glob("working/**")) |