小编Neo*_*Neo的帖子

使用 Geopandas 绘制缺失值

nan我的 shapefile在某些列(例如 GDP)上有一些缺失值(用 表示)。当绘制而不处理这些缺失值时,图例显示如下:

在此输入图像描述

这不是我想要的。因此,我用字符串“missing”替换缺失值,然后重做绘图。毫不奇怪,我收到了这样的错误消息TypeError: '<' not supported between instances of 'str' and 'float'

我的问题是: 1. Geopandas 如何处理缺失值?它将缺失值存储在字符串或其他类型的数据中吗?2.如何保留这些缺失值并使用图例标签重新绘制以显示缺失值?

plot nan geopandas

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

geopandas 绘制的图例填充了斜线

我使用不同的颜色和图案在 PA 地图上显示三个县。中心县由斜线表示,使用hatch='\\'. 但是我很难在图例上显示这种模式。

我有点知道这行不通,但我尝试过Line2D([0],[0],color='white',hatch='\\',lw=4,label='Centre County'),但遇到了诸如“舱口不是属性”之类的错误。

%matplotlib inline

import geopandas as gpd
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D

fig, ax = plt.subplots(1,figsize=(8,8))

pa.plot(ax=ax,color='white',edgecolor='grey')
centre.plot(ax=ax,color='white',hatch='\\\\\\\\',edgecolor='black')
pike.plot(ax=ax,color='grey')
perry.plot(ax=ax,color='red')

LegendElement = [
                 Line2D([0],[0],color='red',lw=4,label='Perry County'),
                 Line2D([0],[0],color='grey',lw=4,label='Pike County'),
                 Line2D([0],[0],color='white',lw=4,label='Centre County')
                ]
ax.legend(handles=LegendElement,loc='upper right')
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

python matplotlib pandas geopandas

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

Google Colab 不打印 for 循环输出

我正在使用 Google Colab,发现它不打印循环输出。请查看以下屏幕截图的输出,单元格运行但没有打印输出。有人遇到这个问题吗,如何解决?谢谢。

for i in range(5):
    print('{0} out of {1} numbers have been printed'.format(i+1,5),end='\r')

Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

printing google-colaboratory

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