我有一个列出值的列表,我得到的值之一是'nan'
countries= [nan, 'USA', 'UK', 'France']
Run Code Online (Sandbox Code Playgroud)
我试图删除它,但我每次都会收到错误
cleanedList = [x for x in countries if (math.isnan(x) == True)]
TypeError: a float is required
Run Code Online (Sandbox Code Playgroud)
当我尝试这个时:
cleanedList = cities[np.logical_not(np.isnan(countries))]
cleanedList = cities[~np.isnan(countries)]
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
Run Code Online (Sandbox Code Playgroud) 我在我的图表中显示了超过40个项目.我只有10种颜色反复显示在图表上.如何生成更多颜色.
plt.pie(f,labels=labels,autopct='%1.1f%%', startangle=90,shadow=True)
Run Code Online (Sandbox Code Playgroud)
我应该添加"color = colors",其中颜色是无限生成的?
我正在努力在 python 中聚合 Json 文件 我使用列表理解来获取所有负责机构
import pandas as pd
import numpy as np
url = "http://311api.cityofchicago.org/open311/v2/requests.json";
d= pd.read_json(url)
ar = [x.get("agency_responsible") for x in d.values()]
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'numpy.ndarray' object is not callable
Run Code Online (Sandbox Code Playgroud)
然后我尝试通过添加 numpy 并处理数组来解决这个问题。
import numpy as np
np.[x.get("agency_responsible") for x in d.values()]
Run Code Online (Sandbox Code Playgroud)
但似乎并没有成功!
我想提取 json 文件的所有值。例如我有这个对象,我想获取所有“文本”值。我怎样才能做到这一点 ?
list= [
{
"text": "contact solution - COUPON",
"listId": "1",
"id": "4",
"leaf": "true"
},
{
"text": "Falafel (bulk)",
"listId": "1",
"id": "161",
"leaf": "true"
},
{
"text": "brita filters",
"listId": "1",
"id": "166",
"leaf": "false"
}
Run Code Online (Sandbox Code Playgroud)
输出:
listText = ["contact solution - COUPON","Falafel (bulk)","brita filters"]
Run Code Online (Sandbox Code Playgroud)
更新:
我从 CSV 文件获取这些数据。
text,listId,id,leaf, jsonfile
"1","is","an","example","{ "text": "contact solution - COUPON", "listId": "1", "id": "4","leaf": "true"}"
"2","is","an","example"," { "text": "Falafel (bulk)","listId": "1", "id": "161", "leaf": "true" }"
"3","is","an","example"," { …Run Code Online (Sandbox Code Playgroud) 我正在处理需要数小时才能执行的复杂查询.我正在使用PSycopg2
通过阅读这篇文章.我补充说:
import os.environ
['PGOPTIONS'] = '-c statement_timeout=1000000'
Run Code Online (Sandbox Code Playgroud)
现在,我每次都收到错误,执行此查询:
import psycopg2
>>> cnn = psycopg2.connect("dbname=test options='-c statement_timeout=1000'")
>>> cur = cnn.cursor()
>>> cur.execute("select pg_sleep(200000)")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
psycopg2.extensions.QueryCanceledError: canceling statement due to statement timeout
Run Code Online (Sandbox Code Playgroud)
我的问题:如何强制应用程序花费很长时间来处理查询?
python ×4
json ×2
numpy ×2
matplotlib ×1
pandas ×1
pie-chart ×1
postgresql ×1
psycopg2 ×1
r ×1
sql ×1