import akshare as ak
import pandas as pd
# 深证最早
df = ak.stock_zh_index_daily(symbol="sz000001")
df['year'] = pd.to_datetime(df['date'])
df['date'] = pd.to_datetime(df['date'])
df.set_index('year',inplace=True)
df.sort_index()
#df.resample('Y').last().index
group = df.groupby(df.index.year)
list(group)
group.agg({'date':'max'})
date
year
1991 1991-12-31
1992 1992-12-31
1993 1993-12-31
1994 1994-12-30
1995 1995-12-29
1996 1996-12-31
1997 1997-12-31
1998 1998-12-31
1999 1999-12-30
2000 2000-12-29
2001 2001-12-31
2002 2002-12-31
2003 2003-12-31
2004 2004-12-31
2005 2005-12-30
2006 2006-12-29
2007 2007-12-28
2008 2008-12-31
2009 2009-12-31
2010 2010-12-31
2011 2011-12-30
2012 2012-12-31
2013 2013-12-31
2014 2014-12-31
2015 2015-12-31
2016 2016-12-30
2017 2017-12-29
2018 2018-12-28
2019 2019-12-31
2020 2020-12-31
2021 2021-12-31
2022 2022-10-17