Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 以0.5的步骤索引数据帧_Python_Pandas - Fatal编程技术网

Python 以0.5的步骤索引数据帧

Python 以0.5的步骤索引数据帧,python,pandas,Python,Pandas,我想添加几个数据帧。它们的指数在0到25之间,以0.5的步长变化。现在,当我尝试添加它们时,索引的解释是不同的,新添加的数据帧的索引顺序是“0到2”,即0.5,1,1.5,10,10.5…19.5,2…等等。所以10比2小,我猜是因为它以1开头,数据帧按第一个值对索引进行排序 我尝试了不同的添加帧的方法: pd.concat([df1,df2,df3…],轴=0) df1+df2+df3 添加(df2,填充值=0)。添加(df3…) 他们都工作。唯一的问题是新的索引把我的框架搞砸了 我当然可以

我想添加几个数据帧。它们的指数在0到25之间,以0.5的步长变化。现在,当我尝试添加它们时,索引的解释是不同的,新添加的数据帧的索引顺序是“0到2”,即0.5,1,1.5,10,10.5…19.5,2…等等。所以10比2小,我猜是因为它以1开头,数据帧按第一个值对索引进行排序

我尝试了不同的添加帧的方法:

pd.concat([df1,df2,df3…],轴=0) df1+df2+df3 添加(df2,填充值=0)。添加(df3…) 他们都工作。唯一的问题是新的索引把我的框架搞砸了

我当然可以在添加帧之前重置索引,然后将索引更改回原来的位置。但是有没有更直接的方法呢

对评论的答复:

Index(['0.5', '1.0', '1.5', '2.0', '2.5', '3.0', '3.5', '4.0', '4.5', '5.0',
       '5.5', '6.0', '6.5', '7.0', '7.5', '8.0', '8.5', '9.0', '9.5', '10.0',
       '10.5', '11.0', '11.5', '12.0', '12.5', '13.0', '13.5', '14.0', '14.5',
       '15.0', '15.5', '16.0', '16.5', '17.0', '17.5', '18.0', '18.5', '19.0',
       '19.5', '20.0', '20.5', '21.0', '21.5', '22.0', '22.5', '23.0', '23.5',
       '24.0', '24.5', '25.0', '25.5', '26.0', '26.5', '27.0', '27.5', '28.0',
       '28.5'],
      dtype='object') Index(['0.5', '1.0', '1.5', '2.0', '2.5', '3.0', '3.5', '4.0', '4.5', '5.0',
       '5.5', '6.0', '6.5', '7.0', '7.5', '8.0', '8.5', '9.0', '9.5', '10.0',
       '10.5', '11.0', '11.5', '12.0', '12.5', '13.0', '13.5'],
      dtype='object') Index(['0.5', '1.0', '1.5', '2.0', '2.5', '3.0', '3.5', '4.0', '4.5', '5.0',
       '5.5', '6.0', '6.5', '7.0', '7.5', '8.0', '8.5', '9.0', '9.5', '10.0',
       '10.5', '11.0', '11.5', '12.0', '12.5', '13.0', '13.5', '14.0', '14.5',
       '15.0', '15.5', '16.0', '16.5', '17.0', '17.5', '18.0'],
      dtype='object')

一个最简单的解决方案是在所有数据帧中将索引转换为
FloatIndex

df1.index = df1.index.astype(float)
df2.index = df2.index.astype(float)
df3.index = df3.index.astype(float)

什么是打印(df1.index,df2.index,df3.index)?我想你需要一些东西。reset_index(),它应该是这样开始的
df=pd.concat([df1,df2,df3…],axis=0)。reset_index(drop=True)
我想把索引保持在半步