0

I want to do something similar to the vlookup in the python. Here is a dataframe I want to lookup for value 'Flow_Rate_Lupa'enter image description here

And here is the dataframe I want to fill the data by looking at the same month+day to fill the missing value. Is there any one to help me to solve how to do this QAQenter image description here

2 Answers 2

2

I usually merge the two data frames and define an indicator, then filter out the values where the indicator says both meaning data is in both data frames.

import pandas as pd

mergedData= pd.merge(df1,df2, how='left' ,left_on='Key1', right_on='Key2', indicator ='Exists')
filteredData = mergedData[mergedData[Exists]='both']
Sign up to request clarification or add additional context in comments.

Comments

1

Use DataFrame.merge with left join and the nreplace missing values by Series.fillna with DataFrame.pop for use and remove column:

df = df2.merge(df1, on=['month','day'], how='left', suffixes=('','_'))
df['Flow_Rate_Lupa'] = df['Flow_Rate_Lupa'].fillna(df.pop('Flow_Rate_Lupa_'))

Comments

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.