0

I have df1 like this:

        id
   0   MC01
   1   MC02
   2   MC03

Then another df2 like this:

   employee   mins
      A        8.0
      B        7.5
      C        6.3
      D        9.1
      E        8.4
      F        6.1

I want to combine both dataframe into matrix like this:

   employee   MC01    MC02    MC03
      A        8.0     8.0     8.0
      B        7.5     7.5     7.5
      C        6.3     6.3     6.3
      D        9.1     9.1     9.1
      E        8.4     8.4     8.4
      F        6.1     6.1     6.1

And this code will running continuously with different value/datashape. Please help me on this matter. Thanks in advance!

1 Answer 1

2

You can do something like this:

df3 = pd.DataFrame()
df3['employee'] = df2['employee']
for col in df1['id']:
    df3[col] = df2['mins']
>>> df3
    employee    MC01    MC02    MC03
0   A   8.0 8.0 8.0
1   B   7.5 7.5 7.5
2   C   6.3 6.3 6.3
3   D   9.1 9.1 9.1
4   E   8.4 8.4 8.4
5   F   6.1 6.1 6.1
Sign up to request clarification or add additional context in comments.

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.