Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Concatenate/Join/Merge two Dataframes
#1
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
Quote
#2
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?
Quote
#3
(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.
Quote
#4
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
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Quote
#5
(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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  append dataframes in loop ghena 1 177 Feb-17-2020, 08:43 PM
Last Post: jefsummers
  Merging two DataFrames based on indexes from two other DataFrames lucinda_rigeitti 0 117 Jan-16-2020, 08:36 PM
Last Post: lucinda_rigeitti
  Compare between 2 DataFrames Nidhesh 2 397 Jul-26-2019, 08:16 AM
Last Post: Nidhesh
  Could anyone help me get the jaccard distance between my dataframes please? :) a_real_phoenix 0 559 Jun-27-2019, 06:01 PM
Last Post: a_real_phoenix
  Two dataframes merged Ecniv 10 1,068 Jun-16-2019, 09:10 PM
Last Post: Ecniv
  Statistical analysis of two dataframes zhl 1 696 Jun-11-2019, 07:26 PM
Last Post: Ecniv
  Interpolate using multiple dataframes Lastwizzle 0 428 May-29-2019, 05:32 PM
Last Post: Lastwizzle
  concatenate mcgrim 1 443 Mar-22-2019, 01:31 PM
Last Post: buran
  Concatenate multiple csv files Oscarca 1 1,014 Nov-05-2018, 11:18 AM
Last Post: Larz60+
  Why can't I merge pandas dataframes learnpython2018 2 1,829 Sep-23-2018, 05:53 PM
Last Post: learnpython2018

Forum Jump:


Users browsing this thread: 1 Guest(s)