python - Select multiple sections of rows by index in pandas -


i have large dataframe gps path , attributes. few sections of path need analyse. subset sections new dataframe. can subset 1 section @ time idea have them , have original index.

the problem similar to:

import pandas pd  df = pd.dataframe({'a':[0,1,2,3,4,5,6,7,8,9],'b':['a','b','c','d','e','f','g','h','i','j']},                   index=range(10,20,)) 

i want o like:

cdf = df.loc[[11:13] & [17:20]] # syntaxerror: invalid syntax 

desired outcome:

     b 11  1  b 12  2  c 13  3  d 17  7  h 18  8  19  9  j 

i know example easy cdf = df.loc[[11,12,13,17,18,19],:] in original problem have thousands of lines , entries removed, listing points rather not option.

one possible solution concat:

cdf = pd.concat([df.loc[11:13], df.loc[17:20]]) print (cdf)      b 11  1  b 12  2  c 13  3  d 17  7  h 18  8  19  9  j 

another solution range:

cdf = df.ix[list(range(11,14)) + list(range(17,20))] print (cdf)      b 11  1  b 12  2  c 13  3  d 17  7  h 18  8  19  9  j 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -