如何索引从n开始的 pandas 数据帧? [英] How to index a pandas data frame starting at n?

查看:73
本文介绍了如何索引从n开始的 pandas 数据帧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从pandas数据框中的n开始索引?

Is it possible to start the index from n in a pandas dataframe?

我将某些数据集另存为csv文件,并希望使用

I have some datasets saved as csv files, and would like to add the column index with the row number starting from where the last row number ended in the previous file.

例如,对于第一个文件,我使用下面的代码可以正常工作,所以我得到了一个输出的csv文件,其行从1到1048574开始,按预期方式:

For example, for the first file I'm using the following code which works fine, so I got an output csv file with rows starting at 1 to 1048574, as expected:

yellow_jan ['index'] = range(1,len(yellow_jan)+ 1)

yellow_jan['index'] = range(1, len(yellow_jan) + 1)

我想对yellow_feb文件执行相同的操作,但是在1048575处开始行索引,依此类推。

I would like to do same for the yellow_feb file, but starting the row index at 1048575 and so on.

感谢任何帮助!

推荐答案

您可以只在结尾处重置索引或定义局部变量,然后在`范围功能。使用读取的每个文件的行数更新变量。

you may just reset the index at the end or define a local variable and use it in `arange' function. update the variable with the numbers of rows for each file you read.

这篇关于如何索引从n开始的 pandas 数据帧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆