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