0

I have a timeseries dataset which has two columns. the first column is timestamp and the second is the data. The timestamp is ordered by minutes and covers the entire year.

Timestamp           Data
1/1/2017   0:00        50
1/1/2017   0:01        80
...
12/31/2017 23:59     100

So now I would like the dataset to be rearranged to a table that each column stands for different days, but rows still stand for data for each minute. The new dataset will be like

      1/1  1/2  1/3 .......  12/31
0:00  50   60   34  .......  67
0:01  34   211  90  .......  90
...
23:59

So is there a way to do this fast?

2
  • You have to try to do something yourself first, and then if you need advice on specific problems then people may be able to help - but they will not jut do the job for you I'm afraid. Commented Feb 23, 2018 at 16:05
  • I am doing it manually. Find the timestamp mark a new day and manually add a new column to move the data around. It is in excel and I know it is silly, so that's why I want to find a more efficient way to do it. Commented Feb 23, 2018 at 16:15

1 Answer 1

2

Begin by splitting your "Timestamp" column into date and time. How to do this depends on whether it's truly a timestamp or a string. If it is a timestamp, do (using 'Date' as the column name to avoid confusion with the pandas builtin 'Timestamp'

df['Day'] = df['Date'].map(pd.Timestamp.date)
df['Time'] = df['Date'].map(pd.Timestamp.time)
del df['Date']

Follow this with a pivot_table:

pd.pivot_table(df, values='Data', index=['Time'], columns=['Day'])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.