Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F68820390
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
Sat, Jun 29, 01:54
Size
1 KB
Mime Type
text/x-python
Expires
Mon, Jul 1, 01:54 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
18635987
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
(
"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"
)
country_clean
=
country_clean
.
replace
(
"' "
,
"'"
)
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