1

I have a csv file that contains the following data.

created_at               hr         bp_dias      bp_sys      weight     
18/05/2015  12:00:05     57
18/05/2015  12:00:05                 79
18/05/2015  12:00:05                               62
18/05/2015  12:00:05                                            83

I'd like to get them all into one single line, like so

 created_at              hr         bp_dias      bp_sys      weight 
 18/05/2015  12:00:05    57          79            62         83

I tried using pandas groupby and tried grouping them according to the time stamp, but that didn't give me the result I wanted.

Here is the code I used.

  df = pd.read_csv('test.csv',parse_dates=True)
  df['created_at'] = pd.to_datetime(df['created_at'],unit='s')
  df = df.set_index('created_at')    
  df = df.groupby([df.index.year,df.index.month,df.index.day])

  print df.head()
1
  • You can just use df = pd.read_csv('test.csv',parse_dates=[0]) you shouldn't need the other lines of code Commented Jun 30, 2015 at 10:38

1 Answer 1

1

You almost had it, groupby 'created_at' and call max() and then reset_index:

In [165]:    
df.groupby('created_at').max().reset_index()

Out[165]:
           created_at  hr  bp_dias  bp_sys  weight     
0 2015-05-18 12:00:05  57       79      62           83
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.