1

i have the following dataframe:

       FAK_ART    FAK_DAT  LEIST_DAT      KD_CRM MW_BW       EQ_NR MATERIAL  \
0         ZPAF 2015-05-18 2015-05-31         D     E  100107  S   
1         ZPAF 2015-05-18 2015-05-31         D     B  100107  S   
2         ZPAF 2015-05-18 2015-05-31         D     E  100108  S   
3         ZPAF 2015-05-18 2015-05-31         D     B  100108  S   
4         ZPAF 2015-05-18 2015-05-31         D     E  100109  S   
5         ZPAF 2015-05-18 2015-05-31         D     B  100109  S   
6         ZPAF 2015-05-18 2015-05-31         D     E  100110  S   
7         ZPAF 2015-05-18 2015-05-31         D     B  100110  S   
8         ZPAF 2015-05-18 2015-05-31         D     E  100111  S 

. . .

387976    ZPAF 2016-02-12 2016-02-29  CP     B  100686   S   
387977    ZPAF 2016-02-12 2016-02-29  CP     B  100686   S   
387978    ZPAF 2016-02-12 2016-02-29  CP     E  100712   S   
387979    ZPAF 2016-02-12 2016-02-29  CP     B  100712   S   
387980    ZPAF 2016-02-12 2016-02-29  CP     E  100735   S   
387981    ZPAF 2016-02-12 2016-02-29  CP     B  100735   S   
387982    ZPAF 2016-02-12 2016-02-29  CP     B  100735   S   
387983    ZPAF 2016-02-12 2016-02-29  CP     E  100748   S   
387984    ZPAF 2016-02-12 2016-02-29  CP     B  100748   S   
387985    ZPAF 2016-02-12 2016-02-29  CP     E  100760   S

now i want to select only the rows with the date 2015-05-31.

i tried little bit around to handle it with date_range but i always get errors:

ValueError: Length of values does not match length of index

or

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

my idea was that:

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

but then i get an error!

How can i fix or solve that?

5
  • 1
    whether the dtype is string or datetime the following should work: data_fakture[data_faktura['LEIST_DAT'] == '2016-01-31'] Commented Aug 1, 2016 at 12:59
  • do i have to assign that on the dataframe again? Commented Aug 1, 2016 at 13:00
  • What do you mean assign? Aren't you trying to filter the df? Commented Aug 1, 2016 at 13:00
  • yes i meant if i have to do it like that: data_faktura = data_faktura[data_faktura['LEIST_DAT'] == '2016-01-31'] Commented Aug 1, 2016 at 13:01
  • yes that should work Commented Aug 1, 2016 at 13:04

1 Answer 1

3

You can set_index from column LEIST_DAT and then select by 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  CP     B  100686   S
2016-02-29    ZPAF  2016-02-12  CP     B  100686   S
2016-02-29    ZPAF  2016-02-12  CP     E  100712   S
2016-02-29    ZPAF  2016-02-12  CP     B  100712   S
2016-02-29    ZPAF  2016-02-12  CP     E  100735   S
2016-02-29    ZPAF  2016-02-12  CP     B  100735   S
2016-02-29    ZPAF  2016-02-12  CP     B  100735   S
2016-02-29    ZPAF  2016-02-12  CP     E  100748   S
2016-02-29    ZPAF  2016-02-12  CP     B  100748   S
2016-02-29    ZPAF  2016-02-12  CP     E  100760   S

Or 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  CP     B  100686   S
2016-02-29    ZPAF  2016-02-12  CP     B  100686   S
2016-02-29    ZPAF  2016-02-12  CP     E  100712   S
2016-02-29    ZPAF  2016-02-12  CP     B  100712   S
2016-02-29    ZPAF  2016-02-12  CP     E  100735   S
2016-02-29    ZPAF  2016-02-12  CP     B  100735   S
2016-02-29    ZPAF  2016-02-12  CP     B  100735   S
2016-02-29    ZPAF  2016-02-12  CP     E  100748   S
2016-02-29    ZPAF  2016-02-12  CP     B  100748   S
2016-02-29    ZPAF  2016-02-12  CP     E  100760   S

You can also select by start and end date:

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         D     E  100107  S
2015-05-31    ZPAF  2015-05-18         D     B  100107  S
2015-05-31    ZPAF  2015-05-18         D     E  100108  S
2015-05-31    ZPAF  2015-05-18         D     B  100108  S
2015-05-31    ZPAF  2015-05-18         D     E  100109  S
2015-05-31    ZPAF  2015-05-18         D     B  100109  S
2015-05-31    ZPAF  2015-05-18         D     E  100110  S
2015-05-31    ZPAF  2015-05-18         D     B  100110  S
2015-05-31    ZPAF  2015-05-18         D     E  100111  S
2016-02-29    ZPAF  2016-02-12  CP     B  100686   S
2016-02-29    ZPAF  2016-02-12  CP     B  100686   S
2016-02-29    ZPAF  2016-02-12  CP     E  100712   S
2016-02-29    ZPAF  2016-02-12  CP     B  100212   S
2016-02-29    ZPAF  2016-02-12  CP     E  100735   S
2016-02-29    ZPAF  2016-02-12  CP     B  100735   S
2016-02-29    ZPAF  2016-02-12  CP     B  100735   S
2016-02-29    ZPAF  2016-02-12  CP     E  100748   S
2016-02-29    ZPAF  2016-02-12  CP     B  100748   S
2016-02-29    ZPAF  2016-02-12  CP     E  100760   S
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.