小编V_s*_*qrt的帖子

Geopandas:如何绘制国家/城市?

我需要在地理图上绘制一些数据。具体来说,我想强调数据来自的国家和州。我的数据集是

    Year    Country State/City
0   2009    BGR     Sofia
1   2018    BHS     New Providence
2   2002    BLZ     NaN
3   2000    CAN     California
4   2002    CAN     Ontario
... ... ... ...
250 2001    USA     Ohio
251 1998    USA     New York
252 1995    USA     Virginia
253 2011    USA     NaN
254 2019    USA     New York
Run Code Online (Sandbox Code Playgroud)

为了创建地理图,我一直在使用geopandas如下:

import geopandas as gpd

shapefile = 'path/ne_110m_admin_0_countries/ne_110m_admin_0_countries.shp'
gdf = gpd.read_file(shapefile)[['ADMIN', 'ADM0_A3', 'geometry']]
gdf.columns = ['country', 'country_code', 'geometry']
Run Code Online (Sandbox Code Playgroud)

然后我合并了两个数据集:

merged = gdf.merge(df, left_on = 'country_code', right_on = …
Run Code Online (Sandbox Code Playgroud)

python plot pandas bokeh geopandas

8
推荐指数
1
解决办法
1344
查看次数

一次热编码期间出现 RunTimeError

我有一个数据集,其中类值以 1 步从 -2 到 2 变化(i.e., -2,-1,0,1,2),其中 9 标识未标记的数据。使用一种热编码

self._one_hot_encode(labels)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:RuntimeError: index 1 is out of bounds for dimension 1 with size 1

由于

self.one_hot_labels = self.one_hot_labels.scatter(1, labels.unsqueeze(1), 1)
Run Code Online (Sandbox Code Playgroud)

错误应该从 引发[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 1, 1, 1, 1, 1, 1],其中我在映射设置中有 9 等于索引 9 到 1。我不清楚如何修复它,即使在浏览了过去的问题和类似问题的答案之后(例如,索引 1 超出范围)对于尺寸 0 和尺寸 1)。涉及错误的部分代码如下:

def _one_hot_encode(self, labels):
    # Get the number of classes
    classes = …
Run Code Online (Sandbox Code Playgroud)

python numpy torch pytorch

6
推荐指数
1
解决办法
1260
查看次数

删除以数字开头的列

我有一个多列以数字开头的数据框。例如,

00am    00pm    02am    03am    10am    10k 11th    12th    13th ... ABC     JOIN
example example example ...       ...        ...       ...     ...  example  example
Run Code Online (Sandbox Code Playgroud)

我想删除所有以数字开头的列

    ... ABC JOIN
...  example  example
Run Code Online (Sandbox Code Playgroud)

我用过strisdigit

df.loc[:,~df.columns.str.isdigit()]
Run Code Online (Sandbox Code Playgroud)

但结果仍然显示以数字开头的列。同样,我应该排除包含数字的列(我会说在这种情况下我应该使用str.contain())。

python string pandas

1
推荐指数
1
解决办法
46
查看次数

标签 统计

python ×3

pandas ×2

bokeh ×1

geopandas ×1

numpy ×1

plot ×1

pytorch ×1

string ×1

torch ×1