我已经浪费了几个小时试图解决这个问题,所以我想是时候问问某人/某人了。
我(认为)我已经卸载了与此相关的所有内容,python然后再次安装。我刚刚安装了python最新版本并用于pip安装pandas. 我也尝试安装它,anaconda但错误仍然存在。我也试过直接从github安装,但没有成功。我正在使用 Windows 10。
C:\Users\m>python -V
Python 3.8.2
C:\Users\m>pip install pandas
Collecting pandas
Downloading https://files.pythonhosted.org/packages/07/12/5a087658337a230f4a77e3d548c847e81aa59b332cdd8ddf5c8d7f11c4a1/pandas-1.0.3-cp38-cp38-win32.whl (7.6MB)
|????????????????????????????????| 7.6MB 3.3MB/s
Collecting pytz>=2017.2 (from pandas)
Downloading https://files.pythonhosted.org/packages/e7/f9/f0b53f88060247251bf481fa6ea62cd0d25bf1b11a87888e53ce5b7c8ad2/pytz-2019.3-py2.py3-none-any.whl (509kB)
|????????????????????????????????| 512kB 3.2MB/s
Collecting python-dateutil>=2.6.1 (from pandas)
Downloading https://files.pythonhosted.org/packages/d4/70/d60450c3dd48ef87586924207ae8907090de0b306af2bce5d134d78615cb/python_dateutil-2.8.1-py2.py3-none-any.whl (227kB)
|????????????????????????????????| 235kB 6.4MB/s
Collecting numpy>=1.13.3 (from pandas)
Downloading https://files.pythonhosted.org/packages/5d/b3/f3543d9919baa11afc24adc029a25997821f0376e5fab75fdc16e13469db/numpy-1.18.2-cp38-cp38-win32.whl (10.8MB)
|????????????????????????????????| 10.8MB 6.4MB/s
Requirement already satisfied: six>=1.5 in c:\users\m\appdata\roaming\python\python38\site-packages (from python-dateutil>=2.6.1->pandas) (1.13.0)
Installing collected packages: pytz, python-dateutil, numpy, pandas
Successfully installed numpy-1.18.2 pandas-1.0.3 …Run Code Online (Sandbox Code Playgroud) 我正在编写一个命令来在数据库中随机创建 500 万个订单。
def constrained_sum_sample(
number_of_integers: int, total: Optional[int] = 5000000
) -> int:
"""Return a randomly chosen list of n positive integers summing to total.
Args:
number_of_integers (int): The number of integers;
total (Optional[int]): The total sum. Defaults to 5000000.
Yields:
(int): The integers whose the sum is equals to total.
"""
dividers = sorted(sample(range(1, total), number_of_integers - 1))
for i, j in zip(dividers + [total], [0] + dividers):
yield i - j
def create_orders():
customers = Customer.objects.all()
number_of_customers …Run Code Online (Sandbox Code Playgroud) 我有一个向RabbitMQ队列发送消息的视图。
message = {'origin': 'Bytes CSV',
'data': {'csv_key': str(csv_entry.key),
'csv_fields': csv_fields
'order_by': order_by,
'filters': filters}}
...
queue_service.send(message=message, headers={}, exchange_name=EXCHANGE_IN_NAME,
routing_key=MESSAGES_ROUTING_KEY.replace('#', 'bytes_counting.create'))
Run Code Online (Sandbox Code Playgroud)
对于我的消费者,我有一个很长的过程来生成 CSV。
def create(self, data):
csv_obj = self._get_object(key=data['csv_key'])
if csv_obj.status == CSVRequestStatus.CANCELED:
self.logger.info(f'CSV {csv_obj.key} was canceled by the user')
return
result = self.generate_result_data(filters=data['filters'], order_by=data['order_by'], csv_obj=csv_obj)
csv_data = self._generate_csv(result=result, csv_fields=data['csv_fields'], csv_obj=csv_obj)
file_key = self._post_csv(csv_data=csv_data, csv_obj=csv_obj)
csv_obj.status = CSVRequestStatus.READY
csv_obj.status_additional = CSVRequestStatusAdditional.SUCCESS
csv_obj.file_key = file_key
csv_obj.ready_at = timezone.now()
csv_obj.save(update_fields=['status', 'status_additional', 'ready_at', 'file_key'])
self.logger.info(f'CSV {csv_obj.name} created')
Run Code Online (Sandbox Code Playgroud)
长过程发生在 内部self._generate_csv,因为 …
我知道如何GROUP BY汇总:
>>> from expenses.models import Expense
>>> from django.db.models import Sum
>>> qs = Expense.objects.order_by().values("is_fixed").annotate(is_fixed_total=Sum("price"))
>>> qs
<ExpenseQueryset [{'is_fixed': False, 'is_fixed_total': Decimal('1121.74000000000')}, {'is_fixed': True, 'is_fixed_total': Decimal('813.880000000000')}]>
Run Code Online (Sandbox Code Playgroud)
但是,如果我想对其他两列做同样的事情,它只返回最后一个:
>>> qs = (
... Expense.objects.order_by()
... .values("is_fixed")
... .annotate(is_fixed_total=Sum("price"))
... .values("source")
... .annotate(source_total=Sum("price"))
... .values("category")
... .annotate(category_total=Sum("price"))
... )
>>> qs
<ExpenseQueryset [{'category': 'FOOD', 'category_total': Decimal('33.9000000000000')}, {'category': 'GIFT', 'category_total': Decimal('628')}, {'category': 'HOUSE', 'category_total': Decimal('813.880000000000')}, {'category': 'OTHER', 'category_total': Decimal('307')}, {'category': 'RECREATION', 'category_total': Decimal('100')}, {'category': 'SUPERMARKET', 'category_total': Decimal('52.8400000000000')}]>
Run Code Online (Sandbox Code Playgroud)
可以只用一个查询而不是三个查询来完成我想要的吗?
预期结果:
<ExpenseQueryset …Run Code Online (Sandbox Code Playgroud) 我正在研究一个基于 python 后端的项目。我将使用 Django 来处理“核心”内容,使用 FastAPI 来处理一些爬虫。Fernet我正在使用模块和自定义Django 将一些数据加密到数据库中Field。
class EncryptedField(models.CharField):
description = "Save encrypted data to DB an read as string on application level."
def __init__(self, *args, **kwargs):
kwargs["max_length"] = 1000
super().__init__(*args, **kwargs)
@cached_property
def fernet(self) -> Fernet:
return Fernet(key=settings.FERNET_KEY)
def get_internal_type(self) -> str:
return "BinaryField"
def get_db_prep_save(
self, value: Any, connection: BaseDatabaseWrapper
) -> Union[memoryview, None]:
value = super().get_db_prep_save(value, connection)
if value is not None:
encrypted_value = self.fernet.encrypt(data=force_bytes(s=value))
return connection.Database.Binary(encrypted_value)
def from_db_value(self, value: bytes, *args) …Run Code Online (Sandbox Code Playgroud) 我正在尝试让隐形的react-google-recaptcha、Formik和yup一起工作。文档说我们应该调用recaptchaRef.current.execute()表单提交,但是如果我们同时使用 Formik 和 yup,只有在所有字段都通过验证模式后才会触发提交逻辑。
基本上,我们需要调用该execute方法,更新验证码值并使用相同的触发事件提交表单。我的问题正是这样:我必须使用两个事件(一个用于方法execute并更新验证码+一个用于提交表单)。
检查此沙箱:https://codesandbox.io/s/keen-mahavira-ont8z? file=/src/App.js
正如您所看到的,只有第二次单击提交按钮才能提交表单...
reactjs invisible-recaptcha yup formik react-google-recaptcha
如果我传递到,我无法将占位符添加到DateInput表单内的小部件。但是,如果我不传递到该字段,其行为就像.'type': 'date'attrs'type': 'date'attrsTextInput
它看起来非常简单,但我不明白出了什么问题。
表格.py
class QueryClientsForm(forms.Form):
initial_date = forms.DateField(
widget=forms.widgets.DateInput(
attrs={'placeholder': 'Initial date...', 'type': 'date', }))
Run Code Online (Sandbox Code Playgroud)
query_clients.html
<div class="container h-50">
<div class="row justify-content-center">
<div class="register_card" style="display: inline-block;">
<form method="POST" action="">
{% csrf_token %}
<div class="input-group">
{{form.initial_date}}
<input class="btn login_btn" type="submit" style="margin-left: 10;" value="SEARCH">
</div>
</form>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我也尝试使用一些javascript但没有成功......
<script>
var initial_date = document.getElementById('id_initial_date')
initial_date.placeholder = 'Initial date...';
</script>
Run Code Online (Sandbox Code Playgroud)
我要改变什么?
django ×5
python ×5
asynchronous ×1
django-forms ×1
encryption ×1
fastapi ×1
fernet ×1
formik ×1
pandas ×1
python-3.x ×1
rabbitmq ×1
reactjs ×1
yup ×1