Add users nicename

After the web opening, admin tells the user that they have to change the password because we don't migrate them from Prestashop. The problem is old users don't have a user nicename, so they can't change their password. We solve this problem by copy the information of "user_login" column to fill nan values in "user_nicename" column of wp_post_meta.

Import library


In [1]:
import pandas as pd

Load the data

users = pd.read_csv('sql_prestashop/wp_users_2018.csv', index_col=False)

Sort dataframe by ID for comfortable look.


In [ ]:
users = users.sort_values('ID')

Select only the the nan value rows.


In [ ]:
users_no_nice = users[users['user_nicename'].isnull()]

Set user_nicename column eqaul to user_login column.


In [ ]:
users_no_nice['user_nicename'] = users_no_nice['user_login']

There are some entries have uppercase letter. Change them to lowercase.


In [ ]:
users_no_nice['user_nicename'] = users_no_nice['user_nicename'].str.lower()

The some entries are in e-mail form. We must change the "@" and "." to "-".


In [ ]:
users_no_nice['user_nicename'] = users_no_nice['user_nicename'].str.replace('@', '-')
users_no_nice['user_nicename'] = users_no_nice['user_nicename'].str.replace('.', '-')

Fill nan value with the "user_no_nice" dataframe.


In [ ]:
users['user_nicename'].fillna(users_no_nice['user_nicename'], inplace=True)

Export to .csv


In [ ]:
users.to_csv('customer_import_to_woo/wp_users_with_nicename.csv', encoding='utf-8', index=False)