To auto-extract the minimum and maximum values of a date in Pandas

Asked 1 months ago, Updated 1 months ago, 1 views

For the time series temperature data shown in the table below, 2000, 2001... and the average value for each year are calculated.

If you know the start-end date,

df['2000-01-04':'2000-12-27'].mean()
df ['2001-01-05':'2001-12-28'].mean()

I think it would be better to specify the value directly, but instead of checking the data one by one, how should I program it if I want to determine start/

I thought I would use df.min(), but I would extract the minimum value of the entire data instead of each year.

date(index) temperature
2000-01-04 -1℃
2000-01-05 0℃
・
・
2000-12-27 8℃
2001-01-05 2℃
2001-01-06 3℃
・
・
2001-12-28 -1℃

python python3 pandas

2022-09-30 11:04

1 Answers

df.resample('1Y').mean()

What about now?

pd.Series(df.index).min()
pd.Series(df.index).max()
df.index[0]
df.index[-1]
df.idxmin()
df.idxmax()

Should I use the maximum and minimum indexes differently depending on the purpose?


2022-09-30 11:04

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.