小编zad*_*zny的帖子

检查具有纬度和经度的地理位置是否在shapefile中

如何检查地理点是否在给定shapefile的区域内?

我设法在python中加载一个shapefile,但无法进一步.

python geocoding geolocation geospatial shapefile

20
推荐指数
3
解决办法
3万
查看次数

如何在pandas和Jupyter Notebook中创建一个带有可点击超链接的表

print('http://google.com') 输出可点击的网址.

如何获取可点击的网址pd.DataFrame(['http://google.com', 'http://duckduckgo.com'])

pandas jupyter-notebook

17
推荐指数
5
解决办法
9622
查看次数

Python pandas:选择列值为null/None/nan的行

如何选择列中的值为none的DataFrame的那些行?

我把这些编码为np.nan和这种类型无法匹配.

In [1]: import numpy as np

In [2]: import pandas as pd

In [3]: df = pd.DataFrame([[1, 2, 3], [3, 4, None]])

In [4]: df
Out[4]: 
   0  1    2
0  1  2  3.0
1  3  4  NaN

In [5]: df = df.fillna(np.nan)

In [6]: df
Out[6]: 
   0  1    2
0  1  2  3.0
1  3  4  NaN

In [7]: df.iloc[1][2]
Out[7]: nan

In [8]: df.iloc[1][2] == np.nan
Out[8]: False

In [9]: df[df[2] == None]
Out[9]: 
Empty …
Run Code Online (Sandbox Code Playgroud)

python pandas

14
推荐指数
1
解决办法
3万
查看次数

如何打印Wordnet的全部内容(最好使用NLTK)?

NLTK提供打印布朗(或古腾堡)语料库中所有单词的功能.但是等效功能似乎不适用于Wordnet.

有没有办法通过NLTK做到这一点?如果没有,怎么可能呢?

这有效:

from nltk.corpus import brown as b
print b.words()
Run Code Online (Sandbox Code Playgroud)

这会导致AttributeError:

from nltk.corpus import wordnet as wn
print wn.words()
Run Code Online (Sandbox Code Playgroud)

python nlp corpus nltk wordnet

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

python请求从谷歌翻译下载不正确的声音文件

我正在使用下面的脚本下载中文老师,但是当我运行它时,我得到的文件与该URL上的文件不同.我认为这是一个编码问题,但是由于我已经指定了UTF-8,我不确定发生了什么.

#!/usr/bin/python
# -*- coding: utf-8 -*-

import requests

url = "http://translate.google.com/translate_tts?tl=zh-CN&q=??"

r = requests.get(url)

with open('test.mp3', 'wb') as test:
    test.write(r.content)
Run Code Online (Sandbox Code Playgroud)

更新:

根据@ abarnert的建议,我检查了文件是带有BOM的UTF-8,并用'idna'测试了代码.

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import requests

url_1 = "http://translate.google.com/translate_tts?tl=zh-CN&q=??"
url_2 = "http://translate.google.com/translate_tts?tl=zh-CN&q=\u8001\u5e2b"

r_1 = requests.get(url_1)
r_1_b = requests.get(url_1.encode('idna'))
r_2 = requests.get(url_2)
r_2_b = requests.get(url_2.encode('idna'))

# This downloads nonsense:
with open('r_1.mp3', 'wb') as test:
    test.write(r_1.content)

# This throws the error specified at bottom:
with open('r_1_b.mp3', 'wb') as test:
    test.write(r_1_b.content)

# This parses the characters individually, …
Run Code Online (Sandbox Code Playgroud)

python encoding google-translate python-requests

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

在#!/ usr/bin/python3之后声明# - * - coding:utf-8 - * - 是多余的吗?

我一直在写:

#!/usr/bin/python3
# -*- coding: utf-8 -*-
Run Code Online (Sandbox Code Playgroud)

但我相信Python3默认使用Unicode.

python utf-8

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

使用Python请求验证Yelp Fusion API

根据Yelp的文档:“要使用访问令牌对API调用进行身份验证,请将Authorization HTTP标头值设置为Bearer access_token。” https://www.yelp.com/developers/documentation/v3/get_started

我使用取得了Yelp API访问令牌requests,但无法进行身份验证:

>>> data = {"grant_type": "client_credentials", "client_id": "foo", "client_secret": "bar"}
>>> r = requests.post("https://api.yelp.com/oauth2/token", data=data)
>>> r
<Response [200]>
>>> r.text
'{"expires_in": 15550795, "token_type": "Bearer", "access_token": "foobar"}'
>>> params = json.loads(r.text)
>>> url = "https://api.yelp.com/v3/autocomplete?text=del&latitude=37.786882&longitude=-122.399972&"
>>> test = requests.get(url, params=params)
>>> test.text
'{"error": {"description": "An access token must be supplied in order to use this endpoint.", "code": "TOKEN_MISSING"}}'
Run Code Online (Sandbox Code Playgroud)

python api yelp python-requests

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

以 json 形式检索 GeoPandas 数据框中的几何图形 [编辑:使用 .to_json()]

将 geojson 文件加载到 GeoPandas 中后,我得到了名为“几何”的预期列/特征,其中包含多边形和多边形。

如何再次将此对象作为 json 或 Python 字典取出?

在它当前的形式中,它是一个geopandas.geoseries.GeoSeries对象。

例如,我需要类似的东西:

geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -73.76336816099996, 40.726165522000031 ], [ -73.762895342999968, 40.726101379000056 ], [ -73.761940118999973, 40.725972874000036 ], [ -73.76074889399996, 40.725792699000067 ] ] ] ] }
Run Code Online (Sandbox Code Playgroud)

在文档中没有看到任何关于此的内容:

http://geopandas.org/data_structs.html#overview-of-attributes-and-methods

geopandas

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

在 Pandas 中创建 NaN 值(而不是 Numpy)

我正在将 .ods 电子表格转换为 Pandas DataFrame。我想删除整个列和行,因为它们只包含“无”。由于“无”是一个str,我有:

pandas.DataFrame.replace("None", numpy.nan)

...我称之为: .dropna(how='all')

pandas等价于numpy.nan吗?

有没有办法使用.dropna()*string "None" 而不是NaN

python pandas

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