1

I have two data-frames with identical columns:

df1 = pd.DataFrame({
    "A": ["B2", "B3", "B6", "B7"],
    "B": ["D2", "D3", "D6", "D7"],
    "C": ["F2", "F3", "F6", "F7"]})

df2 = pd.DataFrame({
        "A": ["A2", "A3", "A6", "A7"],
        "B": ["E2", "E3", "E6", "E7"],
        "C": ["Z2", "Z3", "Z6", "Z7"]})

I am trying to find a way to combine the two DFs in a new data-frame, wherein each cell combines the strings from the equivalent positions in df1 and df2; for example, column A at index position 0 would be the string "B2A2". The resulting data-frame would look something like this:

-----------------------------------
     A           B           C
-----------------------------------
  "B2A2"       "D2E2"      "F2Z2"
  "B3A3"       "D3E3"      "F3Z3"
  "B6A6"       "D6E6"      "F6Z6"
  "B7A7"       "D7E7"      "F7Z7"
-----------------------------------

I have tried looking at the Pandas documentation for merge and concat, but neither seem to do what I need.

1 Answer 1

4

Do you mean

df1 + df2

Output:

      A     B     C
0  B2A2  D2E2  F2Z2
1  B3A3  D3E3  F3Z3
2  B6A6  D6E6  F6Z6
3  B7A7  D7E7  F7Z7
Sign up to request clarification or add additional context in comments.

1 Comment

Feel rather foolish but yes, that's exactly what I needed!!

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.