0

I have below data in Python

import pandas as pd

var1 = pd.DataFrame([0,1,2,3,4])
var2 = pd.DataFrame([6,7,8,9,10])
var = pd.concat([var1 , var2], axis = 1)
days = pd.date_range("2018-01-01", periods=5, freq="D")

Now I want to create a time series for var with index days and then extract subset of var that falls between '2018-01-02' & '2018-01-04'

Is there any way to achieve this using pandas?

Any pointer will be very helpful

smci
  • 32,567
  • 20
  • 113
  • 146
Bogaso
  • 2,838
  • 3
  • 24
  • 54
  • @smci if you like you can adding your thought in that post ~ – BENY Jan 09 '22 at 02:54
  • See [Select DataFrame rows between two dates](https://stackoverflow.com/questions/29370057/select-dataframe-rows-between-two-dates) pandas has [`DataFrame.truncate()`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.truncate.html) for selecting by date-index between certain dates. (Make your index a pd.Timestamp , pandas has lots of helpful date/datetime-aware functions, gets the sort order right, handles intervals etc. etc.) (Yes you could use a simple string index instead of a proper Timestamp, but it's worse for all sorts of reasons). – smci Jan 09 '22 at 02:56

0 Answers0