import pandas as pd
pd.merge(df1, df2, on="Name")
#Only rows are kept for which common keys are found in both data frames.
#In case you want to keep all rows from the left data frame and only add values from df2
#where a matching key is available, you can use how="left":
pd.merge(df1, df2, on="Name", how="left")
In [2]: df
Out[2]:
A B
0 p1 1
1 p1 2
2 p3 3
3 p2 4
In [3]: df.loc[df['B'] == 3, 'A']
Out[3]:
2 p3
Name: A, dtype: object
In [4]: df.loc[df['B'] == 3, 'A'].iloc[0]
Out[4]: 'p3'
In [300]:
df.loc[df['colA'] == 'a', 'colC'] = df['colB']
df['colC'] = df['colC'].fillna(0)
df
Out[300]:
id colA colB colC
0 0 a 13 13
1 1 a 52 52
2 2 b 16 0
3 3 a 34 34
4 4 b 946 0