Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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
Pandas python数据帧索引_Pandas_Python 2.7 - Fatal编程技术网

Pandas python数据帧索引

Pandas python数据帧索引,pandas,python-2.7,Pandas,Python 2.7,我有一个数据框 df = pd.DataFrame(carData) df.column['models'] #df.ffill() This is where i need to fill the amount of columns i want to add with previous value 数据看起来像 models 1 honda 2 ford 3 chevy models 1

我有一个数据框

df = pd.DataFrame(carData)
df.column['models']
#df.ffill() This is where i need to fill the amount of columns i want to add with previous value
数据看起来像

          models
1         honda
2         ford
3         chevy
          models
1         honda
2         ford
3         chevy
4         chevy
5         chevy
我想添加一个索引,但将其数值保持在某个数字,并将模型列向前填充到最后一个值。例如,上面的数据集有3个条目,我想添加一个总共有5个条目的数据集,它应该是这样的

          models
1         honda
2         ford
3         chevy
          models
1         honda
2         ford
3         chevy
4         chevy
5         chevy
与方法='ffill'一起使用或添加ffill:

如果为默认范围索引:

与方法='ffill'一起使用或添加ffill:

如果为默认范围索引:

使用及

使用及

N= 5
df.reindex(range(N)).ffill()

    models
0   honda
1   ford
2   chevy
3   chevy
4   chevy