0

I have data

   id
30046
30049
30040
30046

And next excel

     id                mail
30049  [email protected]  
30046  [email protected]    
30040  [email protected]    

I want to change id from 1 file to mail from 2 excel. Desire output

id  
[email protected]   
[email protected] 
[email protected]
[email protected]

I try

for (id1, id2, mail) in zip(ids1, ids2, mails):
    if id1 == id2:
        ids1.replace(id1, mail)
3
  • Do you want to change the Excel files or just print out the emails? Commented Jun 23, 2016 at 10:38
  • @doctorlove, I need to change df, df = pd.read_excel('name.xlsx'), but don't want to change excel Commented Jun 23, 2016 at 10:40
  • OK, can you add 'df' to the code above? It's not mentioned Commented Jun 23, 2016 at 10:43

1 Answer 1

2

I think you need map column id in df1 by Serie created by set_index from df2:

print (df1)
      id
0  30046
1  30049
2  30040
3  30046

print (df2)
      id                     mail
0  30049  [email protected]
1  30046        [email protected]
2  30040        [email protected]

df1['id'] = df1.id.map(df2.set_index('id')['mail'])
print (df1)
                        id
0        [email protected]
1  [email protected]
2        [email protected]
3        [email protected]
Sign up to request clarification or add additional context in comments.

4 Comments

and may suggest to me to the same example? If I have in columns with quantity of hours, for example 3 and I should add it to column with string like 17/Jun/2016:06:25:05, i want to get 17/Jun/2016:09:25:05, i can use your example, but what I shoud do, to make it datetime type
I think you can create new question, please add sample and desired output if simple pd.to_datetime(df['date_col']) doesnt work.
Can you say, I have similar question, I should change one column from another, but I should change that and to new value add last. I do df['id'] = df.id.map(status.set_index('mail')['status' + ' ' + df.id]) but it returns ValueError: cannot index with vector containing NA / NaN values

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.