我正在以2000 Hz的频率记录数据,这意味着每0.5毫秒我就有另一个数据点。但是我的记录软件只能以1毫秒的精度记录,因此这意味着我在使用float类型的数据帧索引中有重复的值。
因此,为了修复重复项,我想向索引的其他每一行添加0.005。我尝试了这个,但是到目前为止它不起作用:
c = df.iloc[:,0] # select the first column of the dataframe
c = c.iloc[::-1] # reverse order so that time is increasing not decreasing
pd.set_option('float_format', '{:f}'.format) # change the print output to show the decimals (instead of 15.55567E9)
i = c.index # get the index of c - the length is 20000
rp = np.matlib.repmat([0, 0.0005], 1, 10000) # create an array to repeat .0005 0 so that we can add 0.005 to every other row
df.set_index(c, …Run Code Online (Sandbox Code Playgroud)