[英]Add column vector to a dataframe of different length
I have a time series, we can call D1, with 63000 rows and 2 columns:我有一个时间序列,我们可以调用 D1,有 63000 行和 2 列:
Time pH
0 1 5.818488
1 2 5.821478
2 3 5.817494
3 4 5.816903
4 5 5.817778
... ... ...
63895 63896 5.759683
63896 63897 5.762894
63897 63898 5.759819
63898 63899 5.765182
63899 63900 5.764498
And I have a column vector, we can call D2, of 1050 rows:我有一个列向量,我们可以称之为 D2,有 1050 行:
Bit
0 1
1 0
2 1
3 0
4 0
... ...
1045 0
1046 0
1047 0
1048 0
1049 0
I want to add the Bit column of D2 to D1 in this way: first value of D2 assigned to first 60 rows of D1, second value of D2 assigned to rows 61-120, and so on:我想以这种方式将 D2 的 Bit 列添加到 D1:D2 的第一个值分配给 D1 的前 60 行,D2 的第二个值分配给第 61-120 行,依此类推:
Time pH Bit
0 1 5.818488 1
1 2 5.821478 1
2 3 5.817494 1
3 4 5.816903 1
4 5 5.817778 1
... ... ...
63895 63896 5.759683 0
63896 63897 5.762894 0
63897 63898 5.759819 0
63898 63899 5.765182 0
63899 63900 5.764498 0
How can I do this?我怎样才能做到这一点?
Simple example, np.repeat()
does what you need简单的例子,
np.repeat()
做你需要的
D2 = np.array([1,2])
np.repeat(D2,60)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.