0

Now I have two different data frames as the below for an example the first table is df1 and the second table is df2 Have table here with two columns and the Col1 is empty

|---------------------|------------------|
|      Col1           |     Col2         |
|---------------------|------------------|
|                     |         1        |
|---------------------|------------------|
|                     |         2        |
|---------------------|------------------|
|                     |         3        |
|---------------------|------------------|
|                     |         4        |
|---------------------|------------------|
|                     |         5        |
|---------------------|------------------|
|                     |         6        |
|---------------------|------------------|
|                     |         7        |
|---------------------|------------------|

and here's another dataframe with one column

|---------------------|
|      col3          |
|---------------------|
|          5          |
|---------------------|
|          6          |
|---------------------|
|          7          |
|---------------------|

So Now I want to fill Col1 in the first table with values for example, I want to make the result like this

|---------------------|------------------|
|      Col1           |     Col2         |
|---------------------|------------------|
|         Value1      |         1        |
|---------------------|------------------|
|         Value1      |         2        |
|---------------------|------------------|
|         Value1      |         3        |
|---------------------|------------------|
|         Value1      |         4        |
|---------------------|------------------|
|         Value2      |         5        |
|---------------------|------------------|
|         Value2      |         6        |
|---------------------|------------------|
|         Value2      |         7        |
|---------------------|------------------|

I mean that I need to create something the below code:

for i in df1.Col2
   if: df1.Col2.values = df2.Col3.values
        #the Col1 value in df1 will be "value2"

   else
       #the Col1 value in df1 will be "value1"

So any know how can I solve this using pandas?

Mahmoud Al-Haroon
  • 2,239
  • 7
  • 36
  • 72

0 Answers0