2

我有两个以日期时间列作为索引的时间序列:

2012-08-10 1.1       2012-08-10 1.1
2012-08-11 1.2       2012-08-11 1.2
2012-08-12 1.8       2012-08-13 1.1
2012-08-14 1.4       2012-08-15 1.3
2012-08-15 1.7       2012-08-16 1.1
2012-08-17 1.6       2012-08-17 1.2
2012-08-18 1.1       2012-08-18 1.1

如何比较它们并获得两个带有日期的时间序列,它们都存在于它们中:

2012-08-10 1.1       2012-08-10 1.1
2012-08-11 1.2       2012-08-11 1.2
2012-08-15 1.7       2012-08-15 1.3
2012-08-17 1.6       2012-08-17 1.2
2012-08-18 1.1       2012-08-18 1.1
4

2 回答 2

5
In [52]: s1.align(s2, join='inner')
Out[52]:
(2012-08-10    1.1
2012-08-11    1.2
2012-08-15    1.7
2012-08-17    1.6
2012-08-18    1.1,
 2012-08-10    1.1
2012-08-11    1.2
2012-08-15    1.3
2012-08-17    1.2
2012-08-18    1.1)
于 2012-10-02T10:13:08.560 回答
1

使用join

$ cat in1
2012-08-10 1.1
2012-08-11 1.2
2012-08-12 1.8
2012-08-14 1.4
2012-08-15 1.7
2012-08-17 1.6
2012-08-18 1.1
$ cat in2
2012-08-10 1.1
2012-08-11 1.2
2012-08-13 1.1
2012-08-15 1.3
2012-08-16 1.1
2012-08-17 1.2
2012-08-18 1.1
$ join in1 in2
2012-08-10 1.1 1.1
2012-08-11 1.2 1.2
2012-08-15 1.7 1.3
2012-08-17 1.6 1.2
2012-08-18 1.1 1.1

编辑:如果要再次拆分两个文件,请执行以下操作:

$ join in1 in2 | awk '{print $1, $2}' > out1
$ join in1 in2 | awk '{print $1, $3}' > out2
$ cat out1
2012-08-10 1.1
2012-08-11 1.2
2012-08-15 1.7
2012-08-17 1.6
2012-08-18 1.1
$ cat out2
2012-08-10 1.1
2012-08-11 1.2
2012-08-15 1.3
2012-08-17 1.2
2012-08-18 1.1

喜欢小工具:)

于 2012-10-02T09:32:04.373 回答