pandas dataframes getting all rows that fall in bewteen two dates

时间:2018-03-25 18:44:59

标签: python pandas dataframe time merge

import pandas as pd
from pandas.io.html import read_html
from datetime import datetime
import time

wiki_fires = pd.read_html("https://en.wikipedia.org/wiki/2017_California_wildfires")
wildfire_df = wiki_fires[1]
wildfire_df.columns = wildfire_df.iloc[0]
wildfire_df = wildfire_df[1:]

wildfire_df["Start Date"] = wildfire_df["Start Date"].apply(lambda x: dateutil.parser.parse(x))

wildfire_df["Containment Date"] = wildfire_df["Containment Date"].apply(lambda x: dateutil.parser.parse(x))
start = "2017-09-01"
end = "2017-09-30"
mask = (wildfire_df["Containment Date"] >= start) & (wildfire_df['Start Date'] <= end)
mask.head()

mask.head() returns a boolean but what i want it to do is return to me the rows in wildfire_df that fall in between start date and date including those dates. any guidance would be appreciated.

0 个答案:

没有答案