5 Replies - 249 Views - Last Post: 24 October 2018 - 06:43 AM Rate Topic: -----

#1 pynew   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-October 18

How toi merge two timeseries columns into a new column in a dataframe?

Posted 19 October 2018 - 06:25 AM

I have two columns that within each cell has timeseries data. I would like to merge these time series data into another column..it is like creating a new dataframe with these two merged columns and adding it into a series. I have attached an image with the current format and desired format for a clearer idea. I have spent 2 days trying a many ways but to no avail.

the closest i have got to is to create the dataframe using the code below

pd.DataFrame({'a': df.loc[9]['A1'],'b':df.loc[9]['A2']})


but that just creates the dataframe.. so now i dont know how to add this dataframe into a new column.
any advice will be much appreciated

This post has been edited by DK3250: 22 October 2018 - 09:39 AM


Is This A Good Question/Topic? 0
  • +

Replies To: How toi merge two timeseries columns into a new column in a dataframe?

#2 DK3250   User is offline

  • Pythonian
  • member icon

Reputation: 488
  • View blog
  • Posts: 1,530
  • Joined: 27-December 13

Re: How toi merge two timeseries columns into a new column in a dataframe?

Posted 19 October 2018 - 08:35 AM

Hi pynew; Welcome to Dream.In.Code; I hope you will find it helpful.

You give us very little to work with.

How do you read the data?
What have you tried? Please show the code.
What is the problem - do you get an error? If so, please show the error message.
Have you checked the documentation: https://pandas.pydat...DataFrame.html?

Please give us more info, it is hard to help without the context.
Was This Post Helpful? 0
  • +
  • -

#3 pynew   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-October 18

Re: How toi merge two timeseries columns into a new column in a dataframe?

Posted 22 October 2018 - 04:46 AM

View PostDK3250, on 19 October 2018 - 08:35 AM, said:

Hi pynew; Welcome to Dream.In.Code; I hope you will find it helpful.

You give us very little to work with.

How do you read the data?
What have you tried? Please show the code.
What is the problem - do you get an error? If so, please show the error message.
Have you checked the documentation: https://pandas.pydat...DataFrame.html?

Please give us more info, it is hard to help without the context.


The attached image shows what I am trying to achieve. I am reading the data that is stored as a hdf file and at this point I am figuring out how to reindex column 'd' into the nested table in 'b'. I have tried to look for examples but most of them are dealing with flat data and not in this format as shown in the image. I would appreciate some help with how to add a Series into a nested Dataframe.

Thank you.

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#4 pynew   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-October 18

Re: How toi merge two timeseries columns into a new column in a dataframe?

Posted 22 October 2018 - 04:58 AM

adding to the post above, i tried this code but it only reindexes 'd' to the timestamps in 'b' but the next thing i am struggling with is to add 'd' into the nested frame in 'b'
Was This Post Helpful? 0
  • +
  • -

#5 DK3250   User is offline

  • Pythonian
  • member icon

Reputation: 488
  • View blog
  • Posts: 1,530
  • Joined: 27-December 13

Re: How toi merge two timeseries columns into a new column in a dataframe?

Posted 22 October 2018 - 08:04 AM

I really don't know if this is what you are looking for; otherwise please explain again:
import pandas as pd

b = {'x' : [1., 2., 3., 4.],
     'y' : [4., 3., 2., 1.],
     'z' : [6., 7., 8., 9.]}

print(pd.DataFrame(b ))

d = {'d' : [9., 8., 7., 6.]}

for key, val in d.items():  # merge of dicts b and c
    b[key] = val

print(pd.DataFrame(b, columns=['x', 'y', 'z', 'd']))


This post has been edited by DK3250: 22 October 2018 - 08:05 AM

Was This Post Helpful? 0
  • +
  • -

#6 pynew   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-October 18

Re: How toi merge two timeseries columns into a new column in a dataframe?

Posted 24 October 2018 - 06:43 AM

Thanks for the suggestion.

Below is what I needed in the end:

df['b']['d'] = row['d'].reindex(df['b'].index, method='nearest',tolerance='10Sec')

I just missed assigning it as a new column in the nested table in 'b'

Thanks for the suggestion.

Below is what I needed in the end:

df['b']['d'] = df['d'].reindex(df['b'].index, method='nearest',tolerance='10Sec')

I just missed assigning it as a new column in the nested table in 'b'
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1