简体   繁体   中英

How to find the min and max values of a csv file based on a different column of dates?

I have a csv file that consists of temperature values in 2 minute intervals for 3 months. First 5 lines can be seen below.

    T1C T2C T1-T2C  U1  U2  Date    year    month   day
0   NaN NaN NaN NaN NaN 2020-04-25  2020    4   25
1   NaN NaN NaN NaN NaN 2020-04-25  2020    4   25
2   NaN NaN NaN NaN NaN 2020-04-25  2020    4   25
3   8,932   6,703   2,229   0,018   0,018   2020-04-25  2020    4   25
4   9,083   6,799   2,284   0,018   0,018   2020-04-25  2020    4   25

I want to get the max values in T1C and lowest values in T2C for each day. Should I do this with groupby, I couldn't think of a way to do it. Thanks in advance.

你可以使用这个:

result = df.groupby('Date').agg({'T1C': 'max', 'T2C': 'min'})

我将按Day分组,然后汇总:

df.groupby('day').agg({'T1C': 'max', 'T2C': 'min'})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM