Python Forum
Concatenate/Join/Merge two Dataframes - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Concatenate/Join/Merge two Dataframes (/thread-23846.html)



Concatenate/Join/Merge two Dataframes - karlito - Jan-20-2020

Hi,

I'm trying to concatenate two Dataframes with the same size but doesn't seem to work. any ideas? links to images
- my Dataframes: https://www.imageupload.net/image/VbexE

result = pd.concat([test_df, pred_df], axis=1).reindex(test_df.index)
result
- result: https://www.imageupload.net/image/VbhW5

Thks


RE: Concatenate/Join/Merge two Dataframes - jefsummers - Jan-20-2020

What are you wanting to do? One source dataframe has a date column, the other does not. What behavior are you expecting from the attempt at merge?


RE: Concatenate/Join/Merge two Dataframes - karlito - Jan-21-2020

(Jan-20-2020, 04:26 PM)jefsummers Wrote: What are you wanting to do? One source dataframe has a date column, the other does not. What behavior are you expecting from the attempt at merge?

Hi,
the first source is the test dataset and the second one is the prediction (predicted values, that is why there is no data column) that I have saved in a dataframe. I want to merge both and have a dataframe like the one in the second image I posted.
About the date column ... is there any tip/trick I can use here.


RE: Concatenate/Join/Merge two Dataframes - perfringo - Jan-21-2020

Totally unclear for me what data you have and how you want to manipulate it.

Want to add column to existing dataframe?

>>> df = pd.DataFrame({'nums': range(5)})                            
>>> df                                                               
   nums
0     0
1     1
2     2
3     3
4     4
>>> df['chars'] = list('abcde')                                      
>>> df                                                               
   nums chars
0     0     a
1     1     b
2     2     c
3     3     d
4     4     e
>>> df['NaNs'] = np.nan                                              
>>> df                                                               
   nums chars  NaNs
0     0     a   NaN
1     1     b   NaN
2     2     c   NaN
3     3     d   NaN
4     4     e   NaN



RE: Concatenate/Join/Merge two Dataframes - karlito - Jan-21-2020

(Jan-21-2020, 11:04 AM)perfringo Wrote: Totally unclear for me what data you have and how you want to manipulate it.

Want to add column to existing dataframe?

>>> df = pd.DataFrame({'nums': range(5)})                            
>>> df                                                               
   nums
0     0
1     1
2     2
3     3
4     4
>>> df['chars'] = list('abcde')                                      
>>> df                                                               
   nums chars
0     0     a
1     1     b
2     2     c
3     3     d
4     4     e
>>> df['NaNs'] = np.nan                                              
>>> df                                                               
   nums chars  NaNs
0     0     a   NaN
1     1     b   NaN
2     2     c   NaN
3     3     d   NaN
4     4     e   NaN

Hi,

I have two Dataframes.
- test_df with 2 columns: date as index and night_cons (see image)
- pred_df with just a column "prediction" (see image)

I'm trying to merge both but when I do it, the final merged Dataframe gives NAN in the prediction column (see image please)

Hi,
I got it ... It was an index issue.
Thank you all.