pandas apply for each row code example
Example 1: pandas apply function to column
df['a'] = df['a'].apply(lambda x: x + 1)
Example 2: pandas each row?
for index, row in df.iterrows():
print(row["c1"], row["c2"])
Example 3: pandas apply function to each row lambda
def EOQ(D,p,ck,ch):
Q = math.sqrt((2*D*ck)/(ch*p))
return Q
ch=0.2
ck=5
df['Q'] = df.apply(lambda row: EOQ(row['D'], row['p'], ck, ch), axis=1)
df
Example 4: pandas apply function to every row
def money_to_float(money_str):
return float(money_str.replace("$","").replace(",",""))
df['SAL-RATE'].apply(money_to_float)
Example 5: pandas each row?
new_df = df.apply(lambda x: x * 2)