Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F77563904
translate_cop_fr_en.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Aug 15, 05:09
Size
1 KB
Mime Type
text/x-python
Expires
Sat, Aug 17, 05:09 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
19888692
Attached To
R10013 cop-mining-participants
translate_cop_fr_en.py
View Options
import
sys
import
pandas
as
pd
def
translate_affiliation_and_category
(
row
):
new_aff
=
country_translations
.
get
(
row
[
"affiliation"
],
row
[
"affiliation"
])
return
pd
.
Series
([
row
[
"name"
],
new_aff
,
row
[
"affiliation_category"
],
row
[
"description"
]],
index
=
[
"name"
,
"affiliation"
,
"affiliation_category"
,
"description"
])
""" translates affiliations and affiliation categories of
a cop csv from french to english
"""
args
=
sys
.
argv
if
len
(
args
)
!=
2
:
sys
.
exit
(
"Please provide one argument that contains the path
\
of the csv cop participant list to translate"
)
filename
=
"../results/participants-csv/"
+
args
[
1
]
# get the translations for the countries
country_translations
=
dict
()
country_translations_df
=
pd
.
read_csv
(
"../data/dictionaries/countries_french.csv"
)
for
index
,
row
in
country_translations_df
.
iterrows
():
country_clean
=
row
[
"fr"
]
.
lower
()
country_clean
=
country_clean
.
replace
(
"le "
,
""
)
.
replace
(
"la "
,
""
)
.
replace
(
"les "
,
""
)
.
replace
(
"l'"
,
""
)
country_clean
=
country_clean
.
replace
(
"é"
,
"e"
)
.
replace
(
"è"
,
"e"
)
.
replace
(
"ê"
,
"e"
)
.
replace
(
"ï"
,
"i"
)
.
replace
(
"ô"
,
"o"
)
if
"("
in
country_clean
:
country_clean
=
country_clean
[:
country_clean
.
index
(
"("
)
-
1
]
country_translations
[
country_clean
]
=
row
[
"en"
]
.
lower
()
print
(
country_translations
)
cop_data
=
pd
.
read_csv
(
filename
,
encoding
=
"utf-8-sig"
)
cop_data
=
cop_data
.
apply
(
translate_affiliation_and_category
,
axis
=
1
)
filename
=
filename
[:
filename
.
index
(
".csv"
)]
filename
+=
"-en.csv"
cop_data
.
to_csv
(
filename
,
encoding
=
"utf-8-sig"
)
Event Timeline
Log In to Comment