0

Two Dataframes:

df1:

           zone_temp_1
Date/Time
15:36:20     73.500000
15:36:40     73.500000
15:37:00     73.400002
15:37:20     73.400002
15:37:40     73.400002
15:38:00     73.400002
15:38:20     73.500000

df2:

           zone_temp_1
Date/Time
15:38:40     73.500000
15:39:00     73.400002
15:39:20     73.400002
15:39:40     73.400002
15:40:00     73.400002

I would like the concatenation to look like this:

           zone_temp_1
Date/Time
15:36:20     73.500000
15:36:40     73.500000
15:37:00     73.400002
15:37:20     73.400002
15:37:40     73.400002
15:38:00     73.400002
15:38:20     73.400002
15:39:20     73.500000
15:39:40     73.500000
15:40:00     73.400002

Using pandas.concat as such "df1= pd.concat([df1, df2])" leaves me with this

                   0  zone_temp_1
Date/Time
15:36:20   73.500000          NaN
15:36:40   73.500000          NaN
15:37:00   73.400002          NaN
15:37:20   73.400002          NaN
15:37:40   73.400002          NaN
15:38:00   73.400002          NaN
15:38:20   73.400002          NaN
15:38:40         NaN    73.500000
15:38:20         NaN    73.500000
15:39:00         NaN    73.400002
15:39:20         NaN    73.400002
15:39:40         NaN    73.400002
15:40:00         NaN    73.400002

This was marked as a repeat question but I have done my due diligence and can not find any solution.

  • @W-B I read through that and did not see the answer to my case explicitly. Care to elaborate? PS: Love the profile pic – KDMcCracken Dec 11 '18 at 21:03
  • Make sure both of the dataframe you are testing same as what you show to us , pd.concat will match the columns and index (depends on axis=0 or axis=1) – BENY Dec 11 '18 at 21:33
  • @W-B I updated it to replicate my EXACT data and results. I am not sure how to edit it to look pretty though. – KDMcCracken Dec 11 '18 at 21:41
  • df1= pd.concat([df1.rename(columns={0:'zone_temp_1'), df2]) – BENY Dec 11 '18 at 21:43
  • @W-B Are you suggesting I replace the "df1= pd.concat([df1, df2])" with that snippet? That would not work as I do not get that '0' column until I attempt concatenate the first time. – KDMcCracken Dec 11 '18 at 21:51
  • You code work fine on my side – BENY Dec 11 '18 at 21:56
  • @W-B You didnt get the same result as I did? (The concat with the NaN fields) – KDMcCracken Dec 11 '18 at 21:58
  • To get what you want, you need to extract the Series from the DataFrame... then you will be able to concatenation the Series.... and recreate a DataFrame if you really need one. Something like result = pd.concat([df1[‘zone_temp_1’],df2[‘zone_temp_1’]]).sort_index() will do the job. Remember that result will be a pd.Series – Christian Tremblay Feb 05 '19 at 03:49

1 Answers1

0

You can do bigdata = df1.append(df2, ignore_index=True)

Turtalicious
  • 430
  • 2
  • 5