2016-08-01 42 views
1

我有以下數據框中選擇從數據幀行:通過DATE_RANGE

 FAK_ART FAK_DAT LEIST_DAT  KD_CRM MW_BW  EQ_NR MATERIAL \ 
0   ZPAF 2015-05-18 2015-05-31   TMD  E 1003507107 G230ETS 
1   ZPAF 2015-05-18 2015-05-31   TMD  B 1003507107 G230ETS 
2   ZPAF 2015-05-18 2015-05-31   TMD  E 1003507108 G230ETS 
3   ZPAF 2015-05-18 2015-05-31   TMD  B 1003507108 G230ETS 
4   ZPAF 2015-05-18 2015-05-31   TMD  E 1003507109 G230ETS 
5   ZPAF 2015-05-18 2015-05-31   TMD  B 1003507109 G230ETS 
6   ZPAF 2015-05-18 2015-05-31   TMD  E 1003507110 G230ETS 
7   ZPAF 2015-05-18 2015-05-31   TMD  B 1003507110 G230ETS 
8   ZPAF 2015-05-18 2015-05-31   TMD  E 1003507111 G230ETS 

。 。 。

387976 ZPAF 2016-02-12 2016-02-29 T-HOME ICP  B 1001022686 A60ETS 
387977 ZPAF 2016-02-12 2016-02-29 T-HOME ICP  B 1001022686 A60ETS 
387978 ZPAF 2016-02-12 2016-02-29 T-HOME ICP  E 1001022712 A60ETS 
387979 ZPAF 2016-02-12 2016-02-29 T-HOME ICP  B 1001022712 A60ETS 
387980 ZPAF 2016-02-12 2016-02-29 T-HOME ICP  E 1001022735 A60ETS 
387981 ZPAF 2016-02-12 2016-02-29 T-HOME ICP  B 1001022735 A60ETS 
387982 ZPAF 2016-02-12 2016-02-29 T-HOME ICP  B 1001022735 A60ETS 
387983 ZPAF 2016-02-12 2016-02-29 T-HOME ICP  E 1001022748 A60ETS 
387984 ZPAF 2016-02-12 2016-02-29 T-HOME ICP  B 1001022748 A60ETS 
387985 ZPAF 2016-02-12 2016-02-29 T-HOME ICP  E 1001022760 A60ETS 

現在我想只選擇日期爲2015-05-31的行。

我想周圍有點與DATE_RANGE處理它,但我總是得到錯誤:

ValueError: Length of values does not match length of index

ValueError: Must specify two of start, end, or periods

我的想法是:

data_faktura['LEIST_DAT'] = pd.date_range('2016-01-31', '2016-01-31') 

後來我得到一個錯誤!

我該如何解決或解決這個問題?

+1

是否dtype是字符串或日期時間的fol lowing should work:'data_fakture [data_faktura ['LEIST_DAT'] =='2016-01-31']' – EdChum

+0

我必須再次分配數據幀嗎? – Damian

+0

你指的是什麼?你不是想過濾df嗎? – EdChum

回答

3

您可以set_indexLEIST_DAT列,然後通過ix選擇:

#change 2016-02-29 to your datetime 
data_fakture = data_fakture.set_index('LEIST_DAT').ix['2016-02-29'] 
print (data_fakture) 
      FAK_ART  FAK_DAT  KD_CRM MW_BW  EQ_NR MATERIAL 
LEIST_DAT                
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  B 1001022686 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  B 1001022686 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  E 1001022712 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  B 1001022712 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  E 1001022735 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  B 1001022735 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  B 1001022735 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  E 1001022748 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  B 1001022748 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  E 1001022760 A60ETS 

或者loc

data_fakture = data_fakture.set_index('LEIST_DAT').loc['2016-02-29'] 
print (data_fakture) 
      FAK_ART  FAK_DAT  KD_CRM MW_BW  EQ_NR MATERIAL 
LEIST_DAT                
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  B 1001022686 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  B 1001022686 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  E 1001022712 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  B 1001022712 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  E 1001022735 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  B 1001022735 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  B 1001022735 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  E 1001022748 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  B 1001022748 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  E 1001022760 A60ETS 

您還可以通過開始和結束日期選擇:

data_fakture = data_fakture.set_index('LEIST_DAT').ix['2015-05-31':'2016-02-29'] 
print (data_fakture) 
      FAK_ART  FAK_DAT  KD_CRM MW_BW  EQ_NR MATERIAL 
LEIST_DAT                
2015-05-31 ZPAF 2015-05-18   TMD  E 1003507107 G230ETS 
2015-05-31 ZPAF 2015-05-18   TMD  B 1003507107 G230ETS 
2015-05-31 ZPAF 2015-05-18   TMD  E 1003507108 G230ETS 
2015-05-31 ZPAF 2015-05-18   TMD  B 1003507108 G230ETS 
2015-05-31 ZPAF 2015-05-18   TMD  E 1003507109 G230ETS 
2015-05-31 ZPAF 2015-05-18   TMD  B 1003507109 G230ETS 
2015-05-31 ZPAF 2015-05-18   TMD  E 1003507110 G230ETS 
2015-05-31 ZPAF 2015-05-18   TMD  B 1003507110 G230ETS 
2015-05-31 ZPAF 2015-05-18   TMD  E 1003507111 G230ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  B 1001022686 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  B 1001022686 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  E 1001022712 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  B 1001022712 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  E 1001022735 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  B 1001022735 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  B 1001022735 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  E 1001022748 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  B 1001022748 A60ETS 
2016-02-29 ZPAF 2016-02-12 T-HOME ICP  E 1001022760 A60ETS 
+0

謝謝你的工作以及;) – Damian