Pandas时间序列指数

2024-09-28 20:35:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过时间序列来得到日、月、年或季度(任何东西)。但我一直收到以下错误:

AttributeError: 'Int64Index' object has no attribute 'day'

我正在为熊猫使用v14 我看过the cookbook tutorial

scd = raw_data[['SCD_LV_YMD']]

     SCD_LV_YMD
0    2000-09-23
1    1999-10-23
2    1999-10-23
3    1989-04-12
4    1989-04-12
5    1989-05-30
6    1989-05-30
7    1989-05-30
8    1996-01-14
9    1996-01-14

索引将提供以下信息:

In [85]:

scd.index
Out[85]:
Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, ...], dtype='int64')

但是当我试着引用那天的时候它给了我一个错误

In [98]:scd.index.day
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-98-718bfa312e31> in <module>()
----> 1 scd.index.day[:-1]

AttributeError: 'Int64Index' object has no attribute 'day'

我用pd.read.csv输入了数据并分析了日期。

它们最初看起来像19891023

raw_data = pd.read_csv('C:\Users\davidlopez\Desktop\Folders\Standard Reports\HR Reports\ERI RNO DATA\DAVEPHIS\\davephis\davefy14.txt',
                       names=[
                                'NM_EMP_LST',
                                'NM_EMP_FST',
                                'NAT_ACTN_1_3',
                                'NAT_ACTN_2_3',
                                'ACTN_DT',
                                'ACTN_YMD',
                                'TYPE_APNT',
                                'ORG_LEV2',
                                'ORG_LEV3',
                                'ORG_LEV4',
                                'ORG_LEV5',
                                'MR_NBR',
                                'POS_OFF_TTL',
                                'APNT_NA_ACTN',
                                'APNT_AUTH_1',
                                'APNT_YMD',
                                'SCD_CSR_YMD',
                                'SCD_LV_YMD',
                                'SSNO',
                                'TENURE_GROUP'], parse_dates=['ACTN_DT','ACTN_YMD','APNT_YMD','SCD_CSR_YMD','SCD_LV_YMD'])

Tags: noorgindexobject错误attributeerrorhasday