Python 从索引中获取值
我有以下索引:Python 从索引中获取值,python,pandas,Python,Pandas,我有以下索引: PeriodIndex(['2018Q3', '2018Q4', '2019Q1', '2019Q2'], dtype='period[Q-MAR]', name='Quarter', freq='Q-MAR') 如何提取值,即['2018Q3','2018Q4','2019Q1','2019Q2']?转换为字符串s,然后转换为列表: p = pd.PeriodIndex(['2018Q3', '2018Q4', '2019Q1', '2019Q2'],
PeriodIndex(['2018Q3', '2018Q4', '2019Q1', '2019Q2'], dtype='period[Q-MAR]', name='Quarter', freq='Q-MAR')
如何提取值,即
['2018Q3','2018Q4','2019Q1','2019Q2']
?转换为字符串
s,然后转换为列表
:
p = pd.PeriodIndex(['2018Q3', '2018Q4', '2019Q1', '2019Q2'],
dtype='period[Q-MAR]', name='Quarter', freq='Q-MAR')
print (p.astype(str).tolist())
['2018Q3', '2018Q4', '2019Q1', '2019Q2']