ループ処理
#リストループ(numpy.arrayも同様
for index, item in enumerate(list1):
print(str(index))
#辞書
for key, value in dict.items():
print (key, value)
for key in dict:
print (key)
for value in dict.values():
print (value)
#Seriesループ
for index, item in srs.iteritems():
print (index, item)
#DF行ループ
for index, row in df.iterrows():
df.at[index, 'square'] = df['value'] ** 2
#DF列ループ
for column_name, item in df.iteritems():
print(type(column_name))
#プログレスパー表示版
#tqdmはアラビア語でprogress
#特にdfのaxis=1は重く、表示してあげると使用感が良くなります
from tqdm import tqdm
for i in tqdm(range(100)):
sleep(0.1)
子要素へループ処理をする場合、
C#などのforeachの感覚で行うと注意。
pythonではオブジェクトごとに
ループ処理の書き方が違います。
最初enumerateをDataFrameに使ってハマりました。
また、辞書はkey, valueのみに対して、
DataFrameは行、列それぞれに対してループが可能。