• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

索引从n开始的 pandas 数据帧

用户头像
it1352
帮助1

问题说明

是否可以从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.

感谢任何帮助!

正确答案

#1

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

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.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfhaej
系列文章
更多 icon
同类精品
更多 icon
继续加载