0

Really new to python, and trying to solve what might be really simple for you guys but would help me wrap my head around this.

I have the following data.

Date         Time          Delta
01/02/2020   9:30:00 AM    .05
01/02/2020   9:30:01 AM    .029
01/02/2020   9:30:02 AM    .033
...

I'm trying to get that into this form

Date        9:30:00 AM   9:30:01: AM   9:30:02 AM
01/02/2020 .05           .029          .033
...

I've tried:

df = pd.read_csv('C:\\Data\\test.csv')
newDF = df[['Date', 'Time', 'Delta']]

res = newDF.pivot(index='Date', columns='Time', values='Delta')

But that doesn't work at all. In-fact gives an error ValueError: Index contains duplicate entries, cannot reshape.

Is this possible only with Pandas?

Valmorgal
  • 109
  • 9
  • the dates are different, how could it be even possible theoretically! let alone using pandas? – oreopot Apr 13 '20 at 04:16
  • @dexter Sorry my mistake I typed that wrong when I was posting it. I have different times for the same day. – Valmorgal Apr 13 '20 at 04:19
  • @anky There will be duplicates. As there are multiple days (ie, 01/02/0202, 01/03/2020 and 9:30AM start time for the next day all in the Time Column). I want to keep the 9:30:00 AM - 3:59:00 PM times – Valmorgal Apr 13 '20 at 04:27
  • sorry i mean date and times. in the example time is unique for a day , but actually there may be 2 or more lines of same date and times. For `pivot` to work , you need unique combination of index and columns , else look at `pivot_table` but then you have to have an aggregation of some sort. – anky Apr 13 '20 at 04:28
  • @anky I think you're probably right but I'm super new at this pandas/python stuff. – Valmorgal Apr 13 '20 at 04:33
  • 1
    No problem , this will help you in understanding more: [How to pivot a dataframe](https://stackoverflow.com/questions/47152691/how-to-pivot-a-dataframe) – anky Apr 13 '20 at 04:34
  • 1
    Sure , closing this question as dupe of that canonical then? Check Question 1 in the answers , it addresses your issue – anky Apr 13 '20 at 04:39

0 Answers0