3

Lets Say I have the following DataFrames:

DATAFRAME 1

    CFOP    Vendas
0   5101    Venda
1   6101    Venda
2   6107    Venda
3   6118    Venda
4   6109    Venda

DATAFRAME 2

    Name    CFOP    Vendas
0   John    5101    10,00
1   Lea     7008    20,00
2   Anthony 6107    15,00
3   Frank   7000    17,00
4   TOM     6109    21,00

I want to make a third Dataframe only if row 1 of Dataframe 1 mathces row 2 from Dataframe 2.

So, the final answer should be:

    Name    CFOP    Vendas
0   John    5101    10,00
2   Anthony 6107    15,00
4   TOM     6109    21,00

I am stuck, I just could get this code which I know it is wrong:

vendas_somente = []

for row in df_entrada:
    if df_entrada['cfo'] in df_venda['CFOP']:
        vendas_somente.append(row)

vendas_somente(10)

Tks

2 Answers 2

1

Or you can use isin

df2.loc[df2.CFOP.isin(df1.CFOP)]
Out[573]: 
      Name  CFOP Vendas
0     John  5101  10,00
2  Anthony  6107  15,00
4      TOM  6109  21,00
Sign up to request clarification or add additional context in comments.

2 Comments

Can you do me a favor and check out my answer here and upvote if you think it's worth it? Thanks!
@piRSquared sure :)
0

You can create it with an inner merge

In[38]: d1[['CFOP']].merge(d2,how='inner',on='CFOP')
Out[38]: 

   CFOP     Name Vendas
0  5101     John  10,00
1  6107  Anthony  15,00
2  6109      TOM  21,00

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.