0

I have a strange problem when merging 2 dataframes. Although both dataframe contain values along the whole index, the merged on has only shows values in one column, e.g. for one of the orginal dataframes. Please see the pictures below for clarification: Single Dataframes

Merged dataframe

As you can see, the index is the same and there are values. I tried to merge, concat and append but I always have the same issue.

Does anybody of you have a clue? Thank you very much in advance! Sebastian

4
  • 1
    Can you post raw data and code rather than screenshots, you can modify the output by doing pd.set_option('display.notebook_repr_html', False) Commented Jan 19, 2015 at 7:54
  • It may also be better to perform a merge in your case: df1.merge(df2, left_index=True, right_index=True, how='outer') Commented Jan 19, 2015 at 7:55
  • At this point it shouldn't make a difference but I can't help you unless you post data and code that allows me (and others) to reproduce your problem Commented Jan 19, 2015 at 8:31
  • Possibly you have to specify the axis keyword? pd.concat([df1, df2], axis=1) Commented Jan 19, 2015 at 9:12

1 Answer 1

1

Perhaps a simple concat would work for you.

data1 = [2, 4, 6, 8, 10, 12]
data2 = [1, 3, 5, 7, 9, 11]

df1 = pd.DataFrame(data1)
df2 = pd.DataFrame(data2)

concat_df = pd.concat([df1, df2], axis=1)

The key is axis=1 which will concatenate the data frames horizontally rather than vertically.

The output looks like:

    0   0
0   2   1
1   4   3
2   6   5
3   8   7
4  10   9
5  12  11
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.