我有一个数据框 df,有 3 列:年、月和日期。我想使用此信息来确定该日期是周末还是工作日以及是一周中的哪一天。
我试图使用下面的代码来确定是周末还是工作日,但它不起作用
from datetime import datetime
from datetime import date
def is_weekend(d = datetime.today()):
return d.weekday() > 4
Run Code Online (Sandbox Code Playgroud)
df['weekend'] = df.apply(lambda x: is_weekend(date(x['Year'], x['Month'], x['Day'])), axis=1)
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
TypeError: cannot convert the series to <class 'int'>
Run Code Online (Sandbox Code Playgroud)
除此之外,我如何知道这个日期是否是一周中的哪一天。
我需要帮助将以下字典转换为 json:
summary = {'model': 'Test', 'devices': '0,1', 'config': {'data': {'name': 'ABC', 'labels': 'outputs/export2_v2', 'cache_in_memory': False, 'validation_size': 192, 'augmentation': {'photometric': {'enable': True, 'primitives': ['random_brightness', 'random_contrast', 'additive_speckle_noise', 'additive_gaussian_noise', 'additive_shade', 'motion_blur'], 'params': {'random_brightness': {'max_abs_change': 50}, 'random_contrast': {'strength_range': [0.3, 1.5]}, 'additive_gaussian_noise': {'stddev_range': [0, 10]}, 'additive_speckle_noise': {'prob_range': [0, 0.0035]}, 'additive_shade': {'transparency_range': [-0.5, 0.5], 'kernel_size_range': [100, 150]}, 'motion_blur': {'max_kernel_size': 3}}}, 'homographic': {'enable': True, 'params': {'translation': True, 'rotation': True, 'scaling': True, 'perspective': True, 'scaling_amplitude': 0.2, 'perspective_amplitude_x': 0.2, 'perspective_amplitude_y': 0.2, 'patch_ratio': 0.85, 'max_angle': 1.57, 'allow_artifacts': True}, 'valid_border_margin': …Run Code Online (Sandbox Code Playgroud) 我有一个类似于下面的数据框。我只需要添加某些列的总和:16 年 1 月、16 年 2 月、16 年 3 月、16 年 4 月和 16 年 5 月。我将这些列放在名为 Months_list 的列表中
--------------------------------------------------------------------------------------
| Id | Name | Jan-16 | Feb-16 | Mar-16 | Apr-16 | May-16 |
| 4674393 | John Miller | 0 | 1 | 1 | 1 | 1 |
| 4674395 | Joe Smith | 0 | 0 | 1 | 1 | 1 |
---------------------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
我的输出应如下所示:
--------------------------------------------------------------------------------------
| Id | Name | Jan-16 | Feb-16 | Mar-16 …Run Code Online (Sandbox Code Playgroud)