我想将“ item_category_name”列中的所有行转换成英文名为“ item_category_en_name”的新列
from googletrans import Translator
import pandas as pd
item_categories = pd.read_csv("/Users/zhang/OneDrive/Documents/Python Scripts/Predict Sales/item_categories.csv")
headers = ['item_category_name', 'item_category_en_name']
translator = Translator()
df = pd.DataFrame(index=range(0,len(item_categories)),columns=headers)
def translate_row(row):
a = translator.translate(row[0])
return pd.Series([a.origin, a.text], headers)
for i, row in enumerate(item_categories['item_category_name'].values):
# Fill empty dataframe with given serie.
df.loc[i] = translate_row(row)
print(df)
但是我显示错误:
AttributeError: 'NoneType' object has no attribute 'group'
有人知道我该怎么解决吗?