2016-03-28 66 views
0

相當新的Python的刪除計數器和有一個小問題...從最新系列

我有一些代碼,這需要一個日期,並返回了一系列前瞻性的工作日。迄今爲止都很好。唯一的問題是,在輸出我有什麼看起來像每一個日期相關聯,以便例如我有這樣的一個數:

0 2001-01-01 
1 2001-01-02 
2 2001-01-03 
3 2001-01-04 
4 2001-01-05 
5 2001-01-08 
6 2001-01-09 
7 2001-01-10 
8 2001-01-11 
9 2001-01-12 
10 2001-01-15 

當我真的看到:

2001-01-01 
2001-01-02 
2001-01-03 
2001-01-04 
2001-01-05 
2001-01-08 
2001-01-09 
2001-01-10 
2001-01-11 
2001-01-12 
2001-01-15 

請參閱下面是我的代碼。非常感謝任何幫助。

def getBusinessDayCalender(startDate,insampleLength,outsampleLength): 

     print('getBusinessDayCalender') 

     from pandas.tseries.offsets import CustomBusinessDay 
     weekmask_europe = 'Mon Tue Wed Thu Fri' 

     bday_europe = CustomBusinessDay(weekmask=weekmask_europe) 

     dt = pd.datetime(startDate.year, startDate.month, startDate.day) 

     dts = pd.date_range(dt, periods=insampleLength+outsampleLength, freq=bday_europe) 

     dates = pd.Series(dts) 
     print(dates) 
     return dates 
+0

你可以嘗試顯示你的變量的類型?是第一個熊貓系列? – dooms

回答

0

這是黑客攻擊。然而,它會運作良好。

>>> data_list 
'0 2001-01-01\n1 2001-01-02\n2 2001-01-03\n3 2001-01-04\n4 2001-01-05\n5 2001-01-08\n6 2001-01-09\n7 2001-01-10\n8 2001-01-11\n9 2001-01-12\n10 2001-01-15' 
>>> [data[data.index('-') - 4:] for data in data_list.split('\n')] 
['2001-01-01', '2001-01-02', '2001-01-03', '2001-01-04', '2001-01-05', '2001-01-08', '2001-01-09', '2001-01-10', '2001-01-11', '2001-01-12', '2001-01-15'] 
0

所有系列(和DataFrames)的熊貓被索引,看到docs.

In [2]: s = pd.Series([0,3,1]) 
     s 
Out[2]: 0 0 
     1 3 
     2 1 
     dtype: int64 

In [3]: s[1] 
Out[3]: 3 

真實數據秒列