嗨,我在与 seaborn 绘制日期时间时遇到问题。我正在尝试使用 x 作为数据类型绘制分类数据,datetime.time
但出现以下错误:
float() argument must be a string or a number, not 'datetime.time'
Run Code Online (Sandbox Code Playgroud)
这是我的 df:
toronto_time description
0 00:00:50 STATS
1 00:01:55 STATS
2 00:02:18 ONLINE
3 00:05:24 STATS
4 00:05:34 STATS
5 00:06:33 OFFLINE
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use('seaborn-colorblind')
plt.figure(figsize=(8,6))
sns.swarmplot('toronto_time', 'description', data=df);
plt.show()
Run Code Online (Sandbox Code Playgroud)
更新:
'toronto_time' 的 dtype 是一个对象。当我使用 pd.to_datetime 时,它会转换为 datetime 但它会添加一个日期。
您好,我需要从 git 存储库的分支安装。我想将其包含在requirements.txt中,以便它可以使用命令安装pip install -r requirements.txt
我所知道的是如何从 master 分支安装(请参阅下面的 git ssh 条目):
这是我的requirements.txt
networkx==2.4
numpy==1.18.1
opencv-python==4.2.0.32
scipy==1.4.1
git+ssh://git@gitlab.com/project/project-utils.git
Run Code Online (Sandbox Code Playgroud)
如果我想从特定分支(1-fix-test
即ssh://git@gitlab.com/project/project-utils.git
.
如何在 ssh 地址中包含分支名称?
我正在用 celery 构建一个 django 应用程序。我尝试编写一个没有容器的 docker-compose 供工作人员使用。在我的 django Dockerfile 中,运行 celery Worker 和 django 应用程序的入口点:
...
python manage.py migrate
celery -A api worker -l INFO --detach
python manage.py runserver 0.0.0.0:8000
Run Code Online (Sandbox Code Playgroud)
celery 将使用此命令运行,但不会使用 django runserver。我在教程中看到他们将 django 容器与woker 容器分开,反之亦然。我没有看到这种分离的解释。我还观察到两个 python 容器(django、worker)具有相同的体积。celery与django环境不同,如何添加任务?在我看来,两个容器将有两个 django 应用程序(相同的卷),其中一个运行 runserver,另一个运行 celery worker。我不明白分离。
我正在使用django-import-export软件包,期望包含位置名称及其经度和纬度的csv文件。
我想从csv解析经度和纬度字段以将其转换为django.contrib.gis.geos.Point
对象,以便可以将其输入到Location
模型的geom
字段中。
# models.py
from django.contrib.gis.db import models
class Location(models.Model):
name = models.CharField(max_length=200)
geom = models.PointField(null=True, blank=True)
def __str__(self):
return self.name
# admin.py
from .models import Location
from import_export import resources
from import_export.admin import ImportExportModelAdmin
class LocationResource(resources.ModelResource):
geom = Field()
latitude = Field()
longitude = Field()
class Meta:
model = Location
fields = ('id','name', 'latitude', 'longitude')
exclude = ('geom')
export_order = ('id', 'name', 'latitude', 'longitude')
def dehydrate_geom(self, data):
return Point(data.longitude, data.longitude)
class LocationAdmin(ImportExportModelAdmin):
resource_class …
Run Code Online (Sandbox Code Playgroud) 我有 3 个变量,即 R、G、B。我想使用 rasterio 基于这三个变量制作一个 PNG 图像。我尝试使用 np.dstack 堆叠 3 个图像并使用结果来写入它。
使用 rasterio,我尝试这样写:
rgb = np.dstack((Nr,Ng,Nb))
finame = "Image_RGB.png"
with rasterio.Env():
with rasterio.open(finame, 'w',
driver='PNG',
height=rgb.shape[0],
width=rgb.shape[1],
count=1,
dtype=rgb.dtype,
nodata=0,
compress='deflate') as dst:
dst.write(rgb, 1)
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误:
ValueError: Source shape (1, 830, 793, 3) is inconsistent
with given indexes 1
Run Code Online (Sandbox Code Playgroud) 您好,我计划部署一个可以记录到电子表格的应用程序。我使用了PyGSheets。
我得到加薪。
raise SpreadsheetNotFound('Could not find a spreadsheet with title %s.' % title)
pygsheets.exceptions.SpreadsheetNotFound: Could not find a spreadsheet with title RSSI Spreadsheet.
Run Code Online (Sandbox Code Playgroud)
在我使用 service_account_file 进行授权之后
gc = pygsheets.authorize(service_account_file='something.json')
Run Code Online (Sandbox Code Playgroud)
但它适用于
gc = pygsheets.authorize(client_secret='client_secret_something.json')
Run Code Online (Sandbox Code Playgroud)
我想使用 service_account_file 以便它能够通过授权过程。
假设我有一个包含第 0、1 列和“未来连接”的 Pandas 数据框。如何将列 0 和 1 设置为一个元组索引:
例如这个数据框:
0 1 Future Connection
6 840 0.0
4 197 1.0
620 979 0.0
Run Code Online (Sandbox Code Playgroud)
将导致:
0 Future Connection
(6, 840) 0.0
(4, 197) 1.0
(620, 979) 0.0
Run Code Online (Sandbox Code Playgroud) 我有两个来自文本文件的数组。通过观察,它看起来完全一样。然而,当我测试两个数组的等价性时,它们失败了 - 元素明智、形状明智等。我使用了此处回答的 numpy 测试。
这是两个矩阵。
import numpy as np
class TextMatrixAssertions(object):
def assertArrayEqual(self, dataX, dataY):
x = np.loadtxt(dataX)
y = np.loadtxt(dataY)
if not np.array_equal(x, y):
raise Exception("array_equal fail.")
if not np.array_equiv(x, y):
raise Exception("array_equiv fail.")
if not np.allclose(x, y):
raise Exception("allclose fail.")
dataX = "MyMatrix.txt"
dataY = "MyMatrix2.txt"
test = TextMatrixAssertions()
test.assertArrayEqual(dataX, dataY)
Run Code Online (Sandbox Code Playgroud)
我想知道两个阵列之间是否真的存在差异,如果没有,是什么导致了失败。
您好,我想将日程表与我的 Flask 应用程序集成,因为我需要执行一些日常任务。我在这里找到的他使用线程在后台运行它。然而,当我在我的上尝试时,我无法使用 Ctrl-C 退出我的应用程序,我使用的是 Windows。我很快就会将其部署到 Heroku 上,有什么问题吗?
还有没有更好的、“人性化”的时间表来为 Flask 做一些日常任务?谢谢。
这是我的代码:
from flask import Flask
from datetime import datetime
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import mysql.connector
from mysql.connector import Error
import schedule
import time
from threading import Thread
app = Flask(__name__)
def job():
print("I'm working...")
def run_schedule():
while True:
schedule.run_pending()
time.sleep(1)
@app.route('/')
def homepage():
return '<h1>Hello World!</h1>'
if __name__ == '__main__':
schedule.every(5).seconds.do(job)
sched_thread = Thread(target=run_schedule)
sched_thread.start()
app.run(debug=True, use_reloader=False)
Run Code Online (Sandbox Code Playgroud) 我正在写一个 python 脚本来计算一些东西。这就是脚本与 dags 文件夹分开的原因。在该脚本中,我必须导入一个文件。但我没有成功,因为它出错了FileNotFoundError。
这是我的目录:
dags/
- my_dag.py
sub_folder/
- __init__.py
- my_functions.py
meta/
- file.csv
Run Code Online (Sandbox Code Playgroud)
my_functions.py 包含我的 DAG 中所需的计算脚本。它必须读取位于元文件夹中的file.csv。
在 my_functions.py 中,我写道:
file_df = pd.read_csv('meta/file.csv')
Run Code Online (Sandbox Code Playgroud)
但找不到该文件。
我正在拦截边界框 ex 的查询参数。?bbox=160.6,-55.95,-170,-25.89
在我的 GeoDjango 应用程序中过滤与 bbox 相交的条目的查询集。我想知道如何从 bbox 或 bbox 对象列表创建几何对象[160.6,-55.95,-170,-25.89]
。
bbox = GEOSGeometry('BBOX [160.6,-55.95,-170,-25.89]')
Run Code Online (Sandbox Code Playgroud) 嗨,我目前有这个情节。现在,此图显示每个刻度的间隔为 3 小时。我想要从 0:00 到 23:59 或回到 0:00 的所有时间,即 00:00、01:00、02:00 ... 23:00、23:59 或 00:00。
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as md
import pandas as pd
df = pd.DataFrame({'toronto_time': ['2018-09-08 00:00:50',
'2018-09-08 01:01:55',
'2018-09-08 05:02:18',
'2018-09-08 07:05:24',
'2018-09-08 16:05:34',
'2018-09-08 23:06:33'],
'description': ['STATS', 'STATS', 'DEV_OL', 'STATS', 'STATS', 'CMD_ERROR']})
df['toronto_time'] = pd.to_datetime(df['toronto_time'], format='%Y-%m-%d %H:%M:%S')
fig, ax = plt.subplots(figsize=(8,6))
plt.plot('toronto_time', 'description', data=df)
ax.set_xlim(df['toronto_time'].min()-pd.Timedelta(1,'h'),
df['toronto_time'].max()+pd.Timedelta(1,'h'))
ax.xaxis.set_major_formatter(md.DateFormatter('%H:%M:%S'))
plt.show()
Run Code Online (Sandbox Code Playgroud)