Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试将timeframe='month'参数传递给我的函数。我尝试使用 lambda 函数应用,但它似乎不起作用。
timeframe='month'
def a(query_date=pd.DatetimeIndex(['2016-12-31']), timeframe = 'month'): a = query_date.to_series().apply(lambda x:x.timeframe) print(a)
关于如何在里面应用我的时间表有什么建议吗?我希望能够使用函数提取日、月或年。
你可以通过使用 dunder 方法来做到这一点,__getattribute__如下所示:
__getattribute__
def fn(query_date=pd.DatetimeIndex(['2016-12-31']), timeframe = 'month'): a = query_date.to_series().apply(lambda x: x.__getattribute__(timeframe)) return a print(fn())