Translate pandas column with TextBlob
Question: I'm trying to read a csv and translate one column that is written in French to
English with the TextBlob package in Python (2.7.10 Mac OS X Yosemite).

However, Python throws the following error message at me:

    
    
    AttributeError: 'Series' object has no attribute 'translate'
    

My Python code:

    
    
    import pandas as pd
    import numpy as np
    from textblob import TextBlob
    
    df = pd.read_csv('france_content.csv')
    df2 = df[['HEADLINE', 'AUTHOR', 'CONTENT']]
    
    TextBlob = df2['CONTENT'].str.strip()
    TextBlob.translate(to="es")
    

On second thought, I actually think I don't need numpy here. But how can I
make pandas to read the content field and have textblob translate this to
English. Preferably placing this in a column named 'English'

EDIT: Changed to:

    
    
    import pandas as pd
    import numpy as np
    from textblob import TextBlob
    
    df = pd.read_csv('france_content.csv')
    
    df['English'] = df['CONTENT'].str.encode('ascii', 'ignore').apply(lambda x:    TextBlob(x.strip()).translate(to='en'))
    

Data is very basic with in column 1 Author name and in column 2 ('CONTENT')
the French text.

I still have the following error:

    
    
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 9: ordinal not in range(128)
    


Answer: import pandas as pd from textblob import TextBlob df =
pd.read_csv('d:\lan.csv') # path to csv file

# add english column in dataframe with converted words

df['english'] = df['structure'].str.encode('ascii', 'ignore').apply(lambda
x:TextBlob(x.strip()).translate(to='en')) df.to_csv("cool.csv")# your
documents folder

this works as required ,thanks

