'translate all columns by adding new columns to the data frame by for loops in python
import pandas as pd
from googletrans import Translator
df = pd.read_excel('file_name.xlsx', sheet_name='Sheet1')
columns_value = df.columns.values
translator = Translator()
for i in columns_value:
j = df[i].apply(translator.translate, src='ar', dest='en').apply(getattr, args=('text',))
df[str(i) + '_en'] = j
df.to_excel('file2.xlsx')
i have a big data and i want translate all the data by adding new column next to every column, i want every new column has the name of the 'pervious column name + _en',and i want that by looping, i have tried to do that with this code and my problem is my code is adding the new columns after the last column in my data, my qusetion is how do i add the new columns next to every column.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
