Assuming I have a column called df.Text
which contains text (more that 1 sentence) and I want to use polyglot Detector
to detect the language and store the value in a new column df['Text-Lang']
how do I ensure I also capture the other details like code
and confidence
testEng ="This is English"
lang = Detector(testEng)
print(lang.language)
returns
name: English code: en confidence: 94.0 read bytes: 1920
but
df['Text-Lang','Text-LangConfidence']= df.Text.apply(Detector)
ends with
AttributeError: 'float' object has no attribute 'encode' and Detector is not able to detect the language reliably.
Am I applying the Detector function incorrectly or storing the output incorrectly or something else?
from polyglot.detect import Detector testEng ="This is English" lang = Detector(testEng) print(lang)
will produce this output Prediction is reliable: True Language 1: name: English code: en confidence: 94.0 read bytes: 1920 Language 2: name: un code: un confidence: 0.0 read bytes: 0 Language 3: name: un code: un confidence: 0.0 read bytes: 0 – Ludly