gpt4 book ai didi

python - 突出显示超过一周的日期单元格!破折号

转载 作者:行者123 更新时间:2023-12-01 07:34:17 36 4
gpt4 key购买 nike

我正在尝试为超过一周前的日期着色。但当我这样做时,它会为所有日期着色。

首先我在破折号代码之前尝试过它,它工作得很好

df = pd.DataFrame(list(collection_jobs.find({"1_Date":{'$regex':Date},"2_Color":"red"}, {'_id': False})))

df.columns = ['Date', 'Color', 'Name', 'Description', 'Last Build', 'Last Build Result', 'Last Failed Build', 'Last Successful Build', 'Last Unsuccessful Build']

print(df['Last Successful Build'])
>>>0 05/07/2019 09:48:29
1 15/07/2019 08:35:59
2 12/06/2019 08:21:46
3 06/07/2019 01:25:00
4 13/07/2019 21:55:00
5 13/07/2019 21:30:00
6 11/07/2019 03:49:00
7 13/07/2019 20:22:00
8 15/06/2019 11:42:00
9 11/07/2019 01:37:00

Name: Last Successful Build, dtype: object


df['Last Successful Build'] = pd.to_datetime(df['Last Successful Build'], format="%d/%m/%Y %H:%M:%S")

week_ago = datetime.today() - timedelta(days=7)

print("")
print(week_ago)
>>>2019-07-10 11:48:40.377170
print("")
print(df['Last Successful Build'])
>>> 0 2019-07-05 09:48:29
1 2019-07-15 08:35:59
2 2019-06-12 08:21:46
3 2019-07-06 01:25:00
4 2019-07-13 21:55:00
5 2019-07-13 21:30:00
6 2019-07-11 03:49:00
7 2019-07-13 20:22:00
8 2019-06-15 11:42:00
9 2019-07-11 01:37:00

Name: Last Successful Build, dtype: datetime64[ns]
print("")
result = df['Last Successful Build'] < week_ago
print(result)
>>>0 True
1 False
2 True
3 True
4 False
5 False
6 False
7 False
8 True
9 False

Name: Last Successful Build, dtype: bool

这是我对其进行过滤/着色的代码

style_data_conditional=[
{
'if': {
'column_id' : 'Last Successful Build',
'filter_query': '{Last Successful Build} < week_ago'
},
'backgroundColor': 'white',
'color': '#ed0909',
},
],

我希望输出能够为结果为真的线条着色。

最佳答案

我已经通过像这样在['Last Success Build']中制作数据来解决这个问题>>> 2019-07-11然后在本周之前,我这样做了:

week_ago = datetime.today() - timedelta(days=7)
week_agoDate = week_ago.strftime("%Y-%m-%d")

最后在你制作数据表的破折号代码中,我将其更改为:

style_data_conditional=[
{
'if': {
'column_id' : 'Last Successful Build',
'filter_query': ('{Last Successful Build} <' + week_agoDate)
},
'backgroundColor': 'white',
'color': '#ed0909',
},
],

关于python - 突出显示超过一周的日期单元格!破折号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57073184/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com