Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
693 B
3
Indexable
Never
# Importing Libraries
import pandas as pd
import numpy as np

# data's stored in dictionary
details = {
	'Column1': [1, 2, 300, 5]
}

details_1 = {
	'Column1': [2, 1, 4, 30],
	'Column2': [22, 11, 44, 300]
}

# creating a Dataframe object
df = pd.DataFrame(details)
df_new = pd.DataFrame(details_1)

# Where method to compare the values
# The values were stored in the new column
# df['new'] = np.where((df['Column1'] == df_new['Column1']), df['Column1'], np.nan)

# apply function
df['New'] = df.apply(lambda x: x['Column1'] if x['Column1'] in df_new['Column1'].values or x['Column1'] in df_new['Column2'].values else -1, axis=1)

# printing the dataframe
print(df)