效率比较:iterrows<itertuples

    1. import pandas as pd
    2. inp = [{'c1':10, 'c2':100}, {'c1':11,'c2':110}, {'c1':12,'c2':120}]
    3. df = pd.DataFrame(inp)
    1. for index, row in df.iterrows():
    2. print(row["c1"], row["c2"])
    1. for row in df.itertuples(index=True, name='Pandas'):
    2. print getattr(row, "c1"), getattr(row, "c2")
    1. def valuation_formula(x, y):
    2. return x * y * 0.5
    3. df['price'] = df.apply(lambda row: valuation_formula(row['x'], row['y']), axis=1)
    1. for i in range(0, len(df)):
    2. print df.iloc[i]['c1'], df.iloc[i]['c2']