我试图通过组合2个CSV文件来更新温度时间序列,这些文件可能有时会出现重复行。熊猫数据帧时间序列丢失重复信息
我试图实施drop_duplicates
,但它不适合我。
这里是什么,我试图做一个例子:
import pandas as pd
import numpy as np
from pandas import DataFrame, Series
dfA = DataFrame({'date' : Series(['1/1/10','1/2/10','1/3/10','1/4/10'], index=[0,1,2,3]),
'a' : Series([60,57,56,50], index=[0,1,2,3]),
'b' : Series([80,73,76,56], index=[0,1,2,3])})
print("dfA")
print(dfA)
dfB = DataFrame({'date' : Series(['1/3/10','1/4/10','1/5/10','1/6/10'], index=[0,1,2,3]),
'a' : Series([56,50,59,75], index=[0,1,2,3]),
'b' : Series([76,56,73,89], index=[0,1,2,3])})
print("dfB")
print(dfB)
dfC = dfA.append(dfB)
print(dfC.duplicated())
dfC.drop_duplicates()
print("dfC")
print(dfC)
这是输出:
dfA
a b date
0 60 80 1/1/10
1 57 73 1/2/10
2 56 76 1/3/10
3 50 56 1/4/10
dfB
a b date
0 56 76 1/3/10
1 50 56 1/4/10
2 59 73 1/5/10
3 75 89 1/6/10
0 False
1 False
2 False
3 False
0 True
1 True
2 False
3 False
dtype: bool
dfC
a b date
0 60 80 1/1/10
1 57 73 1/2/10
2 56 76 1/3/10
3 50 56 1/4/10
0 56 76 1/3/10
1 50 56 1/4/10
2 59 73 1/5/10
3 75 89 1/6/10
如何更新时间序列重叠数据,而不必重复?
嘿比尔:检查了这一点http://stackoverflow.com/questions/13035764/remove-rows-with-duplicate-indices-pandas-dataframe-and-timeseries – 2014-09-18 18:36:30
而不是说“它不适合我”,它将会 有助于描述*为什么*它不起作用。你会得到例外,不好的结果还是没有回应? – skrrgwasme 2014-09-18 18:39:33