【问题标题】:trying to use for loop to generate each month in a table尝试使用 for 循环在表中生成每个月
【发布时间】:2018-07-22 15:15:37
【问题描述】:

我在 panda/python 中创建了一个表,以创建一个以月份为列的表,月份/年份将显示在该列中。我一直在努力让它一个月又一个月地显示,所以让我们说一月然后二月。但我面临的问题是,它在整个专栏中一直显示相同的月份和年份,正如您所看到的那样,月份三月一直出现在整个专栏中。

这是我用过的for循环

    month_count = 0 

    for row_num in range (4,20):
    # TABLE 1
    vsr_tracker.write_formula(
    'B' + str(row_num), 
    '=DATE(2016,2+{0},1)'.format(month_count))
              row_num + 1))

as you can see on the screenshot that it the month march has been printed throughout the column

【问题讨论】:

    标签: python excel for-loop


    【解决方案1】:

    您的程序不会将月份增加 +1,您必须添加到循环中的日期。 如果您还想将天数增加 1,则也必须将天数增加。

    【讨论】:

    • 尝试增加month_count,方法是在vsr_tracker.write_formula之前添加month_count += 1
    • 如果有效,请将答案标记为正确答案,以便我们知道它已解决。
    • 没问题很乐意帮忙:)
    猜你喜欢
    • 1970-01-01
    • 2013-12-16
    • 2011-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-07
    • 1970-01-01
    相关资源
    最近更新 更多