Reputation: 157
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:
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
Upvotes: 0
Views: 4191
Reputation: 5074
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
Upvotes: 1