所以我正在尝试学习绘制Choropleth贴图。我使用了一个样本数据集,但结果为空。请您看一下并告诉我有什么问题,因为我对语法进行了交叉检查并且不理解为什么它不显示我的数据。我包括了数据集标题和我编写的代码,如下所示:
if(isset($_FILES["files"])) {
$name = $_FILES["files"]["name"][0];
$tmp = $_FILES["files"]["tmp_name"][0];
$path = "";
do { $newName = str_replace(".uexp", "", $name) . "-" . generateRandomString(); $path = "../filestore/$newName.uexp"; } while(file_exists($path));
move_uploaded_file($tmp, $path);
$str = file_get_contents($path);
$byteArray = unpack("C*", $str);
$_SESSION["Name"] = $name;
$_SESSION["Path"] = $path;
$_SESSION["File"] = serialize($byteArray);
}
答案 0 :(得分:0)
您需要提供STATE缩写(DC,AL,...)而不是Names。 我遇到了同样的问题。更改它后,它起作用了。 您可以使用以下代码将名称转换为缩写
def convert_state_name(name):
cd=str(name)
us_state_abbrev = {
"Alabama":"AL"
"Alaska":"AK"
"Arizona":"AZ"
"Arkansas":"AR"
"California":"CA"
"Colorado":"CO"
"Connecticut":"CT"
"Delaware":"DE"
"Washington DC":"DC"
"Florida":"FL"
"Georgia":"GA"
"Hawaii":"HI"
"Idaho":"ID"
"Illinois":"IL"
"Indiana":"IN"
"Iowa":"IA"
"Kansas":"KS"
"Kentucky":"KY"
"Louisiana":"LA"
"Maine":"ME"
"Maryland":"MD"
"Massachusetts":"MA"
"Michigan":"MI"
"Minnesota":"MN"
"Mississippi":"MS"
"Missouri":"MO"
"Montana":"MT"
"Nebraska":"NE"
"Nevada":"NV"
"New Hampshire":"NH"
"New Jersey":"NJ"
"New Mexico":"NM"
"New York":"NY"
"North Carolina":"NC"
"North Dakota":"ND"
"Ohio":"OH"
"Oklahoma":"OK"
"Oregon":"OR"
"Pennsylvania":"PA"
"Rhode Island":"RI"
"South Carolina":"SC"
"South Dakota":"SD"
"Tennessee":"TN"
"Texas":"TX"
"Utah":"UT"
"Vermont":"VT"
"Virginia":"VA"
"Washington":"WA"
"West Virginia":"WV"
"Wisconsin":"WI"
"Wyoming":"WY"
return us_state_abbrev[cd]
df['STATE_CD'] = df.Names.apply(lambda x:convert_state_name(x))
最后,您可以将locations = df ['Names']替换为locations = df ['STATE_CD']
希望这会有所帮助。