xxxxxxxxxx
cols = ['foo', 'bar', 'new']
df['combined'] = df[cols].apply(lambda row: '_'.join(row.values.astype(str)), axis=1)
xxxxxxxxxx
new_df = pd.merge(A_df, B_df, how='left', left_on=['A_c1','c2'], right_on = ['B_c1','c2'])
xxxxxxxxxx
#suppose you have two dataframes df1 and df2, and
#you need to merge them along the column id
df_merge_col = pd.merge(df1, df2, on='id')
xxxxxxxxxx
import pandas as pd
T1 = pd.merge(T1, T2, on=T1.index, how='outer')
xxxxxxxxxx
df["station"] = df["End station"].combine_first(df["Start station"])
df.drop(["End station", "Start station"], 1, inplace=True)
xxxxxxxxxx
# First dataframe with three columns
dlist=["vx","vy","vz"]
df=pd.DataFrame(columns=dlist)
df["vx"]=df1["v2x"]
df["vy"]=df1["v2y"]
df["vz"]=df1["v2z"]
# second dataframe with three columns
dlist=["vx","vy","vz"]
df0=pd.DataFrame(columns=dlist)
df0["vx"]=df2["v1x"]
df0["vy"]=df2["v1y"]
df0["vz"]=df2["v1z"]
# Here with concat we can create new dataframe with garther both in one
# YOU CAN PUT SOME VALUES IN EACH AND CHECK IT
# WHAT INSIDE THE CONCAT MUST BE A LIST OF DATAFRAME
v = pd.concat([df,df0])
xxxxxxxxxx
df = pd.DataFrame({'col1':[0,1,2], 'col2':[0,1,2], 'col3':[0,1,2]})
df
col1 col2 col3
0 0 0 0
1 1 1 1
2 2 2 2
df['col1'], df['col2'], df['col3'] = zip(*df.apply(lambda r: (1, 2, 3), axis=1))
df
col1 col2 col3
0 1 2 3
1 1 2 3
2 1 2 3
xxxxxxxxxx
import pandas as pd
df = {'col_1': [0, 1, 2, 3],
'col_2': [4, 5, 6, 7]}
df = pd.DataFrame(df)
df[[ 'column_new_1', 'column_new_2','column_new_3']] = [np.nan, 'dogs',3] #thought this wo