Created
July 7, 2021 11:39
-
-
Save ahmed4end/341496e2e52743d75ae3112b2021a41f to your computer and use it in GitHub Desktop.
extract column value based on another column pandas dataframe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
file1 = pd.read_csv('./n/oregonhie_descriptive_vars.csv') | |
file2 = pd.read_csv('./n/oregonhie_inperson_vars.csv') | |
file2['treatment'] = file2['person_id'] | |
def proccess(key): | |
a = file1.loc[file1['person_id'] == key, 'treatment'].iloc[0] | |
return a | |
file2['treatment']= file2['treatment'].apply(proccess) | |
file2.to_csv('output.csv', encoding='utf-8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment