Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to slice dataframe based on daterange in pandas

In [15]: df = pd.DataFrame([1, 2, 3], index=[dt.datetime(2013, 1, 1), dt.datetime(2013, 1, 3), dt.datetime(2013, 1, 5)])

In [16]: df
Out[16]: 
            0
2013-01-01  1
2013-01-03  2
2013-01-05  3

In [22]: start = df.index.searchsorted(dt.datetime(2013, 1, 2))

In [23]: end = df.index.searchsorted(dt.datetime(2013, 1, 4))

In [24]: df.iloc[start:end]
Out[24]: 
            0
2013-01-03  2
Comment

PREVIOUS NEXT
Code Example
Python :: python split sentence into words 
Python :: encode labels in scikit learn 
Python :: libreoffice add row at the end of table 
Python :: python read column data from text file 
Python :: The `.create()` method does not support writable nested fields by default. Write an explicit `.create()` method for serializer `room_api.serializers.roomSerializer`, or set `read_only=True` on nested serializer fields. 
Python :: count values in array python 
Python :: python check if type 
Python :: iqr in python 
Python :: highlight max value in table pandas dataframe 
Python :: how to find csrf token python 
Python :: python argparse include default information 
Python :: pandas query on datetime 
Python :: plt axis label font size 
Python :: python get screen size 
Python :: full screen jupyter notebook 
Python :: list mean python 
Python :: python datetime add one week 
Python :: django unique_together 
Python :: python read and delete line from file 
Python :: blender python get selected object 
Python :: display Surface quit 
Python :: pyAudioAnalysis 
Python :: remove columns that contain certain names in pandas 
Python :: The operands of the logical operators should be boolean expressions, but Python is not very strict. Any nonzero number is interpreted as True. 
Python :: Python - Count the Number of Keys in a Python Dictionary 
Python :: tkinter starter code 
Python :: python close browser 
Python :: pandas to_csv no index 
Python :: pytest parametrize 
Python :: how to use variables in string in python 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =