Here is a simplified dataframe that I'm using.
+----+---------------+-------+
|col1| col2| col3|
+----+---------------+-------+
| a| Hello World!| en |
+----+---------------+-------+
Using this dataframe, I take col3's row value and subtract it from a another set to get a list like so:
for row in collect:
lang = set([row['col3']])
req_languages = set(['en','zh-Hans','ko','ja'])
translate_list=list(req_languages-language)
The list is the languages I need to send as a parameter to the API. So for a, translate_list would be ['zh','ko','ja']. col2 is what is going to be translated and is in the body.
The api response then is going to return 3 translations and will look like...
"translations": [
{
"text": "世界您好!",
"to": "zh-Hans"
},
{
"text": "전 세계 여러분 안녕하세요!",
"to": "ko"
},
{
"text": "ハローワールド!",
"to": "ja"
}
]
The output then should look like:
+----+-------------------------+---------+
|col1| col2| col3|
+----+-------------------------+---------+
| a| Hello World!| en |
| a| ハローワールド!| ja |
| a| 전 세계 여러분 안녕하세요!| ko |
| a| 世界您好| zh-Hans |
+----+-------------------------+---------+
How can I manipulate the response to either insert new rows or construct a new dataframe to match the one above?
Note: The actual dataframe has many rows, so I need to send the value from each to row. As well as this call will be getting made thousands of times per day.