擅长:python、mysql、java
<p>用<code>to_period</code>和freq'W-Wed'一起改变一周的开始。你知道吗</p>
<pre><code>s = df['invoiceDate'].dt.to_period('W-Wed').dt.week
df['Week_Num'] = (s - s.min() + 1)
</code></pre>
<p><strike>df['Week\u Num']=(df['invoiceDate'])。日期到时间('W-Wed')。日期周-
df['invoiceDate']。日期到时间('W-Wed')。日期周最小值() + 1)
</strike></p>
<p>输出:</p>
<pre><code> productID invoiceDate Week_Num
0 1 2017-07-18 1
1 2 2017-10-17 14
2 3 2017-08-20 6
3 4 2017-09-05 8
4 5 2017-08-20 6
5 6 2017-11-08 17
6 7 2017-09-17 10
7 8 2017-11-10 18
8 9 2017-08-14 5
9 10 2017-08-24 7
</code></pre>