-1

The title might not be very accurate, but I have two dataframes that I am adding together. The second dataframe is a copy of the first but I would like the Index and IDs to be continuous, so when the 45th row is reached and the first row of the second dataframe is added on, the first index is 46.enter image description here

I have been able to find multiple ways to get the indices to be continuous so ignore that part for now. Mostly need the duplicated entries (i.e. the ID column) to start at 46. I believe this would be some sort of renaming panda. Here is an example of the two dataframes.

enter image description here

JakeP
  • 77
  • 6
  • 2
    Please, don't use image. Provide data as plain text to be reproducible easily. – Corralien Oct 05 '21 at 21:47
  • **[Don't Post Screenshots](https://meta.stackoverflow.com/questions/303812/)**. This question needs a [SSCCE](http://sscce.org/). Always provide a [mre], with **code, data, errors, current output, and expected output, as [formatted text](https://stackoverflow.com/help/formatting)**. It's likely the question will be down-voted and closed. You're discouraging assistance, as no one wants to retype data/code, and screenshots are often illegible. [edit] the question and **add text**. Plots are okay. See [How to provide a reproducible dataframe](https://stackoverflow.com/questions/52413246). – Trenton McKinney Oct 06 '21 at 00:26
  • I am new to Stack, but that makes sense and I appreciate the feedback and tips. – JakeP Oct 06 '21 at 16:09

2 Answers2

0

The following should do the work, assuming that the IDs start counting from 1 in the duplicate['ID']:

duplicate2['ID'] += len(duplicate)
final_df = pd.concat([duplicate, duplicate2], ignore_index=True)
tzinie
  • 717
  • 5
  • 9
0

If you just want a unique index, you could use reset_index at the end of your script.

Just add the line:

result = duplicate2.reset_index(drop=True)
Buz
  • 11
  • 3