s1 vector has 150 values
s2 vector has 800 values
我希望使用熊猫使s1信号的长度与s2的长度相同,但同步却出错(在堆栈的开头堆叠的s1的AL1值为零,其余向量为零)
s1Time = [.0 , .2 , .4 , .6 , .8 , 1.0]
s1Value = [ 0 , 19 , 43 , 62 , 75 , 95 ]
s2Time = [.0 , .1 , .2 , .3 , .4 , .5 , .6 , .7 , .8 , .9 , 1.0]
s2Value = [ 0 , 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 , 100 ]
s1T = pd.Series(s1Time)
s1V = pd.Series(s1Value)
s2T = pd.Series(s2Time)
s2V = pd.Series(s2Value)
newIndex = s1T.index.union(s2T.index)
s1V = s1V.reindex(newIndex).interpolate(method='index')
s2V = s2V.reindex(newIndex).interpolate(method='index')
myData = {'s2T':s2T ,'s1V': s1V , 's2V':s2V}
DF = pd.DataFrame(myData)
DF = DF[['s2T', 's1V', 's2V']]
sheet_name = 'sheet1'
DF.to_excel(writer, sheet_name=sheet_name,startrow=0 , startcol=0)
workbook = writer.book
worksheet = writer.sheets[sheet_name]
这是上面代码的输出:
我应该怎么做才能获得此输出:
另一个相关问题,如何将NaN值更改为插值,因此s1V曲线很平滑。
答案 0 :(得分:0)
使用s2T
作为索引,然后加入:
s1V = pd.Series(s1Value, index=s1Time)
s2V = pd.Series(s2Value, index=s2Time)
df = s2V.to_frame('s2V').join(s1V.rename('s1V'))
然后您可以重置索引:
df = df.reset_index()
最后插值:
df['s1V'] = df['s1V'].interpolate()