-1

I am working with Python Pandas and I have a following table that consists of many rows:

Date X        X     Date Y     Y
0 2014-03-31-   0.390-  2014-04-24- 1.80    
1 2014-04-01-   0.385-  2014-04-25- 1.75

What I want to do is for every index(row), take the value of x and y from every column in the row and make new rows from them and have something like this:

0 2014-03-31    0.390
1 2014-04-24    1.80 

The reason why I am trying to do this is that I want to interpolate between those 2 dates

I tried different merging, remerging and playing with the dataframe but it didn't really help

Tiw
  • 4,749
  • 13
  • 21
  • 32
a_zh
  • 1

1 Answers1

0

You can try the following:

new_df = pd.DataFrame()
for index, row in df.iterrows():
    first_date = row['Date X']
    second_date = row['Date Y']
    x = row['X']
    y = row['Y']
    to_add = pd.DataFrame(data={'Dates': [first_date, second_date], 'params': [x, y]})
    new_df = new_df.append(to_add)
print(new_df)

, where new_df is the new dataframe with all data and df is the original one.

clarapuga
  • 1
  • 1