How to extract countries from a text? Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?How can I safely create a nested directory in Python?Extracting extension from filename in PythonHow do I sort a dictionary by value?How to make a chain of function decorators?How to make a flat list out of list of listsHow do I list all files of a directory?Unable to extract city names from a text using geograpy(Python)
RIP Packet Format
Is it accepted to use working hours to read general interest books?
Why do people think Winterfell crypts is the safest place for women, children & old people?
Where/What are Arya's scars from?
TV series episode where humans nuke aliens before decrypting their message that states they come in peace
What is /etc/mtab in Linux?
My admission is revoked after accepting the admission offer
How would you suggest I follow up with coworkers about our deadline that's today?
Processing ADC conversion result: DMA vs Processor Registers
What is the definining line between a helicopter and a drone a person can ride in?
Writing a T-SQL stored procedure to receive 4 numbers and insert them into a table
Determinant of a matrix with 2 equal rows
How would it unbalance gameplay to rule that Weapon Master allows for picking a fighting style?
What's called a person who works as someone who puts products on shelves in stores?
What is the evidence that custom checks in Northern Ireland are going to result in violence?
Getting AggregateResult variables from Execute Anonymous Window
Was Objective-C really a hindrance to Apple software development?
How can I wire a 9-position switch so that each position turns on one more LED than the one before?
Are there existing rules/lore for MTG planeswalkers?
What was Apollo 13's "Little Jolt" after MECO?
"Working on a knee"
Is a self contained air-bullet cartridge feasible?
Will I lose my paid in full property
Raising a bilingual kid. When should we introduce the majority language?
How to extract countries from a text?
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?How can I safely create a nested directory in Python?Extracting extension from filename in PythonHow do I sort a dictionary by value?How to make a chain of function decorators?How to make a flat list out of list of listsHow do I list all files of a directory?Unable to extract city names from a text using geograpy(Python)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I use Python 3 (I also have Python 2 installed) and I want to extract countries or cities from a short text.
For example, text = "I live in Spain"
or text = "United States (New York), United Kingdom (London)"
.
The answer for countries:
- Spain
- [United States, United Kingdom]
I tried to install geography
but I am unable to run pip install geography
. I get this error:
Collecting geography Could not find a version that satisfies the
requirement geography (from versions: ) No matching distribution found
for geography
It looks like geography
only works with Python 2.
I also have geopandas
, but I don't know how to extract the required info from text using geopandas.
python python-3.x nltk geography
add a comment |
I use Python 3 (I also have Python 2 installed) and I want to extract countries or cities from a short text.
For example, text = "I live in Spain"
or text = "United States (New York), United Kingdom (London)"
.
The answer for countries:
- Spain
- [United States, United Kingdom]
I tried to install geography
but I am unable to run pip install geography
. I get this error:
Collecting geography Could not find a version that satisfies the
requirement geography (from versions: ) No matching distribution found
for geography
It looks like geography
only works with Python 2.
I also have geopandas
, but I don't know how to extract the required info from text using geopandas.
python python-3.x nltk geography
geography is supposed to support Python 3, if you have errors report them at the open github issue. That's how packages get fixed. It helps if you specify what OS, OS version, Python version, and python distribution and version (e.g. anaconda? brew? etc.) you're using, also what version of pip.
– smci
Feb 4 '18 at 21:58
add a comment |
I use Python 3 (I also have Python 2 installed) and I want to extract countries or cities from a short text.
For example, text = "I live in Spain"
or text = "United States (New York), United Kingdom (London)"
.
The answer for countries:
- Spain
- [United States, United Kingdom]
I tried to install geography
but I am unable to run pip install geography
. I get this error:
Collecting geography Could not find a version that satisfies the
requirement geography (from versions: ) No matching distribution found
for geography
It looks like geography
only works with Python 2.
I also have geopandas
, but I don't know how to extract the required info from text using geopandas.
python python-3.x nltk geography
I use Python 3 (I also have Python 2 installed) and I want to extract countries or cities from a short text.
For example, text = "I live in Spain"
or text = "United States (New York), United Kingdom (London)"
.
The answer for countries:
- Spain
- [United States, United Kingdom]
I tried to install geography
but I am unable to run pip install geography
. I get this error:
Collecting geography Could not find a version that satisfies the
requirement geography (from versions: ) No matching distribution found
for geography
It looks like geography
only works with Python 2.
I also have geopandas
, but I don't know how to extract the required info from text using geopandas.
python python-3.x nltk geography
python python-3.x nltk geography
edited Feb 4 '18 at 20:54
joris
66.4k22161154
66.4k22161154
asked Feb 4 '18 at 10:57
MarkusMarkus
8132736
8132736
geography is supposed to support Python 3, if you have errors report them at the open github issue. That's how packages get fixed. It helps if you specify what OS, OS version, Python version, and python distribution and version (e.g. anaconda? brew? etc.) you're using, also what version of pip.
– smci
Feb 4 '18 at 21:58
add a comment |
geography is supposed to support Python 3, if you have errors report them at the open github issue. That's how packages get fixed. It helps if you specify what OS, OS version, Python version, and python distribution and version (e.g. anaconda? brew? etc.) you're using, also what version of pip.
– smci
Feb 4 '18 at 21:58
geography is supposed to support Python 3, if you have errors report them at the open github issue. That's how packages get fixed. It helps if you specify what OS, OS version, Python version, and python distribution and version (e.g. anaconda? brew? etc.) you're using, also what version of pip.
– smci
Feb 4 '18 at 21:58
geography is supposed to support Python 3, if you have errors report them at the open github issue. That's how packages get fixed. It helps if you specify what OS, OS version, Python version, and python distribution and version (e.g. anaconda? brew? etc.) you're using, also what version of pip.
– smci
Feb 4 '18 at 21:58
add a comment |
1 Answer
1
active
oldest
votes
you could use pycountry for your task (it also works with python 3):
pip install pycountry
import pycountry
text = "United States (New York), United Kingdom (London)"
for country in pycountry.countries:
if country.name in text:
print(country.name)
Cool. But it will not work with abbreviations, right? Do you know something additional for recognizing abbreviations and passing them to country names?
– Markus
Feb 4 '18 at 11:25
For example,BVI
->British Virgin Islands
– Markus
Feb 4 '18 at 11:27
every country object has the attributes alpha_2 and alpha_3 which are abbreviations of the country. (E.g: Germany.alpha_2 = DE, Germany.alpha_3 = DEU)
– matyas
Feb 4 '18 at 11:31
1
I hope that that can cover your use case see also: pypi.python.org/pypi/pycountry
– matyas
Feb 4 '18 at 11:32
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48607339%2fhow-to-extract-countries-from-a-text%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
you could use pycountry for your task (it also works with python 3):
pip install pycountry
import pycountry
text = "United States (New York), United Kingdom (London)"
for country in pycountry.countries:
if country.name in text:
print(country.name)
Cool. But it will not work with abbreviations, right? Do you know something additional for recognizing abbreviations and passing them to country names?
– Markus
Feb 4 '18 at 11:25
For example,BVI
->British Virgin Islands
– Markus
Feb 4 '18 at 11:27
every country object has the attributes alpha_2 and alpha_3 which are abbreviations of the country. (E.g: Germany.alpha_2 = DE, Germany.alpha_3 = DEU)
– matyas
Feb 4 '18 at 11:31
1
I hope that that can cover your use case see also: pypi.python.org/pypi/pycountry
– matyas
Feb 4 '18 at 11:32
add a comment |
you could use pycountry for your task (it also works with python 3):
pip install pycountry
import pycountry
text = "United States (New York), United Kingdom (London)"
for country in pycountry.countries:
if country.name in text:
print(country.name)
Cool. But it will not work with abbreviations, right? Do you know something additional for recognizing abbreviations and passing them to country names?
– Markus
Feb 4 '18 at 11:25
For example,BVI
->British Virgin Islands
– Markus
Feb 4 '18 at 11:27
every country object has the attributes alpha_2 and alpha_3 which are abbreviations of the country. (E.g: Germany.alpha_2 = DE, Germany.alpha_3 = DEU)
– matyas
Feb 4 '18 at 11:31
1
I hope that that can cover your use case see also: pypi.python.org/pypi/pycountry
– matyas
Feb 4 '18 at 11:32
add a comment |
you could use pycountry for your task (it also works with python 3):
pip install pycountry
import pycountry
text = "United States (New York), United Kingdom (London)"
for country in pycountry.countries:
if country.name in text:
print(country.name)
you could use pycountry for your task (it also works with python 3):
pip install pycountry
import pycountry
text = "United States (New York), United Kingdom (London)"
for country in pycountry.countries:
if country.name in text:
print(country.name)
edited Mar 9 at 4:23
TerryA
44.5k882104
44.5k882104
answered Feb 4 '18 at 11:21
matyasmatyas
1,4941320
1,4941320
Cool. But it will not work with abbreviations, right? Do you know something additional for recognizing abbreviations and passing them to country names?
– Markus
Feb 4 '18 at 11:25
For example,BVI
->British Virgin Islands
– Markus
Feb 4 '18 at 11:27
every country object has the attributes alpha_2 and alpha_3 which are abbreviations of the country. (E.g: Germany.alpha_2 = DE, Germany.alpha_3 = DEU)
– matyas
Feb 4 '18 at 11:31
1
I hope that that can cover your use case see also: pypi.python.org/pypi/pycountry
– matyas
Feb 4 '18 at 11:32
add a comment |
Cool. But it will not work with abbreviations, right? Do you know something additional for recognizing abbreviations and passing them to country names?
– Markus
Feb 4 '18 at 11:25
For example,BVI
->British Virgin Islands
– Markus
Feb 4 '18 at 11:27
every country object has the attributes alpha_2 and alpha_3 which are abbreviations of the country. (E.g: Germany.alpha_2 = DE, Germany.alpha_3 = DEU)
– matyas
Feb 4 '18 at 11:31
1
I hope that that can cover your use case see also: pypi.python.org/pypi/pycountry
– matyas
Feb 4 '18 at 11:32
Cool. But it will not work with abbreviations, right? Do you know something additional for recognizing abbreviations and passing them to country names?
– Markus
Feb 4 '18 at 11:25
Cool. But it will not work with abbreviations, right? Do you know something additional for recognizing abbreviations and passing them to country names?
– Markus
Feb 4 '18 at 11:25
For example,
BVI
-> British Virgin Islands
– Markus
Feb 4 '18 at 11:27
For example,
BVI
-> British Virgin Islands
– Markus
Feb 4 '18 at 11:27
every country object has the attributes alpha_2 and alpha_3 which are abbreviations of the country. (E.g: Germany.alpha_2 = DE, Germany.alpha_3 = DEU)
– matyas
Feb 4 '18 at 11:31
every country object has the attributes alpha_2 and alpha_3 which are abbreviations of the country. (E.g: Germany.alpha_2 = DE, Germany.alpha_3 = DEU)
– matyas
Feb 4 '18 at 11:31
1
1
I hope that that can cover your use case see also: pypi.python.org/pypi/pycountry
– matyas
Feb 4 '18 at 11:32
I hope that that can cover your use case see also: pypi.python.org/pypi/pycountry
– matyas
Feb 4 '18 at 11:32
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48607339%2fhow-to-extract-countries-from-a-text%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
geography is supposed to support Python 3, if you have errors report them at the open github issue. That's how packages get fixed. It helps if you specify what OS, OS version, Python version, and python distribution and version (e.g. anaconda? brew? etc.) you're using, also what version of pip.
– smci
Feb 4 '18 at 21:58