我有一个数据框架,其中我将索引设置为国家/地区。然而,也有一些国家集团,如撒哈拉以南非洲(国际开发协会和国际复兴开发银行国家)或中东和北非(国际开发协会和国际复兴开发银行国家)。我想删除它们。我只想让国家留下来。
imput dataframe示例,其中索引为:
Antigua and Barbuda
Angola
Arab World
想要输出数据帧:
Antigua and Barbuda
Angola
我的想法是使用pycountry,但是它什么也不做。
countr=list(pycountry.countries)
for idx in df.index:
if idx in
我试图让我的用户按国家搜索数据。用户将以他们的母语输入国家名称。然而,我的数据库只包含每个国家的alpha2代码。
我目前的做法是:
user_input = "France"
country_code = pycountry.countries.get(name=user_input).alpha2 # u'FR'
如果用户输入是用英语写的,这就很好了。由于数据是以用户首选的语言显示的,她也希望以自己喜欢的语言搜索数据。
通过将gettext与pycountry的地区结合使用,我能够以用户首选的语言显示国家名称:
# example for a German
我有一个带有国家名称和与之对应的值的DataFrame。我使用以下代码将国家/地区转换为代码: import pycountry
input_countries = happiness_data["Country or region"]
countries = {}
for country in pycountry.countries:
countries[country.name] = country.alpha_2
codes = [countries.get(country, 'Unknown code') for country in i
我使用Python 3(我还安装了Python 2),我想从一个简短的文本中提取国家或城市。例如,text = "I live in Spain"或text = "United States (New York), United Kingdom (London)"。
各国的答案是:
西班牙
美国、联合王国
我试图安装geography,但无法运行pip install geography。我知道这个错误:
收集地理信息无法找到满足地理需求的版本(来自版本:),无法为地理找到匹配的发行版
看起来geography只适用于Python2。
我
我正在尝试将国家名称转换为所需的国家代码。
例如:
United Kingdom : UK
我尝试了以下几种方法:
import pycountry
user_input = raw_input(': ')
mapping = {country.name: country.alpha2 for country in pycountry.countries}
print mapping.get(user_input)
我认为我可能误解了文档,因为我收到了以下错误:
mapping = {country.name: country.alpha2 for country in
我想使用一些没有舍入的预定义查找到NHibernate中的数据库。
基本上,我希望有这样的代码:
public class Countries
{
static Countries() {
Australia = new Country
{
Id = 14,
Description = "Australia"
}
}
public static Country Austrlia { get; protected set }
}
然后编写以下代码片段:
address.Country = Coun
我是新手,我正在尝试扭转下面的关系,所以这是我的问题,基本上我已经创建了两个模型国家和联系人 这里我要做的是在联系人模型中创建一个函数,以便我可以获取对用户ID的国家/地区访问。这是我的联系人模型 <?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Contact extends Model
{
public function country(){
return $this->belongsTo('App\Country');
}
} 所以现在我想颠倒这
我需要将国家代码列表转换为国家数组。以下是我到目前为止所做的工作。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
pickerViewArray = [[NSMutableArray alloc] init]; //pickerViewArray is of type NSArray;
pickerViewArray =[NSLocale ISOCountryCodes];
}
如何在dataframe中存储国家名称
import pandas as pd
import pycountry
countries = pd.DataFrame()
for i in list(pycountry.countries):
i=dict(i)
print(i)
countries['alpha_3'] = i['alpha_3']
countries['name'] = i['name']
countries['original_name'] = i[
我使用从获得的以下代码从他们的俄罗斯名字中获取国家代码。
def get_country_code(russian_name):
gettext.translation('iso3166', pycountry.LOCALES_DIR, languages=['RU']).install()
country_code = ''.join([country.alpha_2 for country in pycountry.countries if _(country.name) == russian_name])
retur
我的练习是编写一个包含两个位置的UNION的查询,这两个SELECT包含列REGION_ID, REGION_NAME, COUNTRY_NAME和"No of Locations“。结果必须是所有国家/地区的列表,其中包含该国家/地区的位置数量。该列表必须按区域ID和国家/地区名称排序。
我不太理解操作符union的逻辑,这个查询的结果必须包含所有国家和地区的列表。我所做的是:
(select reg.region_id, reg.region_name, coun.country_name
from countries coun, regions reg
where reg.reg
我有国家、地区、县、镇的数据,目前我正在决定两种模式设计(如果有更好的,请告诉我)。
我首先想到
国家/地区
- Id
- Name
地域
- Id
- CountryId
- Name
县
- Id
- RegionId
- Name
小镇
- Id
- CountyId
- Name
然而,要想得到一个国家的所有城镇,你必须有3个内部连接来进行过滤。我想这样可以,但可能会很贵吧?
另一种设计是:
国家/地区
- Id
- Name
地域
- Id
- Name
县
- Id
- Na