Question: I do not want to manually type in thousands of posts from my old website on the front end of my new website. I simply want to merge the database from the old into the new website in phpmyadmin. I'll tweak the tables to suit the new software afterwards.

1. I think there are only four tables that need to be merged for my purposes: wp\_postmeta, wp\_posts, wp\_usermeta and wp\_users.
2. The old website is still live, and the most recent post is post\_id 28,556. So to be safe and neat, I want all my new website post ids to begin at 30,000.

I found this code which is sort of what I'm looking for, but not really: <https://gist.github.com/jazzsequence/99dbee218c1b9a84df0d>. This code simply adds +1 to every row, ignoring all associations with usermeta, users, post\_ids inside postmeta etc. It cannot be used.

If you are unable to answer the question in it's entirety (it will help thousands of wordpress users if you do it properly), please tell me how to add 30,000 to every value in a given column. eg. If the column is called ID and the existing values are 1,2,4,9,13,24,25,26,28, then they would become 30001,30002,30004,30009,30013,30024,30025,30026,30028.

Answer: 
**Setup** 

Consider the dataframes `inventory` and `replace_with`

```
inventory = pd.DataFrame(dict(Partnumbers=['123AAA', '123BBB', '123CCC']))

replace_with = pd.DataFrame(dict(
        oldPartnumbers=['123AAA', '123BBB', '123CCC'],
        newPartnumbers=['123ABC', '123DEF', '123GHI']
    ))

```

**Option 1**  

*`map`* 

```
d = replace_with.set_index('oldPartnumbers').newPartnumbers
inventory['Partnumbers'] = inventory['Partnumbers'].map(d)

inventory

  Partnumbers
0      123ABC
1      123DEF
2      123GHI

```

---

**Option 2**  

*`replace`* 

```
d = replace_with.set_index('oldPartnumbers').newPartnumbers
inventory['Partnumbers'].replace(d, inplace=True)

inventory

  Partnumbers
0      123ABC
1      123DEF
2      123GHI

```
This solution is relatively fast - it uses pandas data alignment and the numpy "copyto" function.

```
import pandas as pd
import numpy as np

df1 = pd.DataFrame({'partNumbers': ['123AAA', '123BBB', '123CCC', '123DDD']})
df2 = pd.DataFrame({'oldPartnumbers': ['123AAA', '123BBB', '123CCC'],
                    'newPartnumbers': ['123ABC', '123DEF', '123GHI']})

# assign index in each dataframe to original part number columns
# (faster than set_index method, but use set_index if original index must be preserved)
df1.index = df1.partNumbers
df2.index = df2.oldPartnumbers
# use pandas index data alignment
df1['updatedPartNumbers'] = df2.newPartnumbers
# use numpy to copy in old part num when a new part num is not found
np.copyto(df1.updatedPartNumbers.values,
          df1.partNumbers.values,
          where=pd.isnull(df1.updatedPartNumbers))
# reset index
df1.reset_index(drop=True, inplace=True)

```

df1:

```
  partNumbers updatedPartNumbers
0      123AAA             123ABC
1      123BBB             123DEF
2      123CCC             123GHI
3      123DDD             123DDD

```