在python中筛选datetime列
我试图动态地子集一个在python中筛选datetime列,python,python-3.x,pandas,dataframe,Python,Python 3.x,Pandas,Dataframe,我试图动态地子集一个datetime列,但仍将列保留在dataframe中,因为该函数将用于UI,但由于某些原因,我在应用该函数后没有看到该列 下面是帮助器函数 def get_df(df, start, end, datetime_col, columns): df = df.loc[(df[datetime_col]>=start) & (df[datetime_col]<= end)][columns] return df 我希望数据帧中包含的date
datetime列
,但仍将列
保留在dataframe
中,因为该函数将用于UI
,但由于某些原因,我在应用该函数后没有看到该列
下面是帮助器函数
def get_df(df, start, end, datetime_col, columns):
df = df.loc[(df[datetime_col]>=start) & (df[datetime_col]<= end)][columns]
return df
我希望数据帧中包含的datetime\u col
与最初一样
这应该行得通
def get_df(df、开始、结束、日期时间列、列):
df=df.loc[(df[datetime\u col]>=start)&(df[datetime\u col]您需要在.loc.Trydf=df.loc[(df[datetime\u col]>=start)&(df[datetime\u col]的列中同时包含这两个内容,$和+?@Pythonista yes.Editted.“+”是将两个列表添加在一起以获得.lochaha中的列列表,我没有看到。非常感谢!我真傻
get_df(df, start=datetime(2020,3,1), end=default_end_date, datetime_col="time_iso8601", columns=["Berlin"]).head()
Berlin
0 0
1 6
2 9
3 19
4 24
def get_df(df, start, end, datetime_col, columns):
df = df.loc[(df[datetime_col]>=start) & (df[datetime_col]<= end)][[columns,datetime_col]]
return df