Pandas Sort
Pandas: ソート Find the unique values in a column and then sort them pandas unique values multiple columns NumPy 配列 ndarray を一次元化(平坦化)する ravel と flatten
Pandas: ソート Find the unique values in a column and then sort them pandas unique values multiple columns NumPy 配列 ndarray を一次元化(平坦化)する ravel と flatten
Poetry : パッケージ依存定義 (Dependency specification) バージョン要件(requirements) 要件 例 意味 Caret requirements ^1.2.3 >=1.2.3 <2.0.0 Tilde requirements ~1.2.3 >=1.2.3 <1.3.0 Wildcard requirements 1.* >=1.0.0 <2.0.0 Inequality requirements < 2 < 2.0.0 Exact requirements ==1.2.3 もしくは 1.2.3 ==1.2.3 @ operator 依存(dependancies) 依存 git dependencies path dependencies url dependencies extras source dependencies python Multiple constraints dependencies 拡張
Elasic Cache for Redis バージョン 1 2 3 4 5 $ redis-cli --version redis-cli 5.0.7 $ redis-server -v Redis server v=5.0.7 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=66bd629f924ac924 接続: 1 REDIS_URL=redis://mycloud-stage-redis-nc.sigrvp.ng.0001.apne1.cache.amazonaws.com:6379/0 1 2 3 $ export $(cat .env|xargs) $ redis-cli -u $REDIS_URL PING PONG Python redis-py: https://github.com/redis/redis-py django-redis: https://github.com/jazzband/django-redis channels_redis: https://github.com/django/channels_redis クラスターモードへの接続 Cluster Client 1 2 3 4 5 6 7 8 9 import logging from redis.cluster import RedisCluster ENDPOINT = "mycloud-stage-redis-test.sigrvp.clustercfg.apne1.cache.amazonaws.com" logging.basicConfig(level=logging.INFO) redis = RedisCluster(host=ENDPOINT, port="6379") if redis.ping(): logging.info("Connected to Redis") django-redis: ...
Celery on ECS 【Python Celery】本番運用時に知っておくべき 10 のこと https://github.com/Alexmhack/Django-Celery-Redis-AWSEB Redis Celery + AWS Redis で使ってみる クラスターモード Redis >= 3.2 ElastiCache for Redis のクラスターモードについて調べてみる SQS broker としてつかえるが、 backend としては使えない(SQS + RabbitMQ/Redis/SQLAlchemy を考える) Celery + SQS on Django on Elastic Beanstalk Deploying Django on AWS: Setting up Celery and SQS Deploying Django Application on AWS with Terraform. Setting up Celery and SQS ECS running celery tasks and celery beat in ECS with Django docker compose ecs deploy aws tutorial: celery incompatible attribute #8040 AWS Batch を検討したけど AWS Fargate を採用した話 Celery Logging celery.app.log Three Ideas to Customise Celery logging handlers 標準出力: ...
ltsv 形式 http://ltsv.org/ https://github.com/hekyou/python-ltsv pip install ltsv To process LTSV files in Python, you can use the ltsv package available on PyPI ². Here is an example of how to use it: 1 2 3 4 5 import ltsv with open('file.ltsv') as f: for record in ltsv.reader(f): print(record) This code will read the LTSV file line by line and print each record as a dictionary ¹. ...
ndjson https://github.com/rhgrant10/ndjson Snowflake: CREATE FILE FORMAT 【Python】Python ~ ndjson を扱う ~ tablib は ndjson をサポートしていない pandas は ndjson を読み込める
pandas: MySQL sqlalchemy で mysqlclient を使うには、まず mysqlclient をインストールする必要があります。次に、SQLAlchemy のエンジン構成で mysqlclient を使用するように設定します。以下は、Qiita の記事 ¹ からの例です。 1 2 3 from sqlalchemy import create_engine engine = create_engine('mysql+mysqldb://user:password@host/dbname', echo=True) また、CData Python Connector for MySQL³ を使用することもできます。これは、SQLAlchemy ORM を使用して Python で MySQL データに連携するためのドライバです。 1 2 from sqlalchemy import create_engine engine = create_engine("mysql+mysqlconnector://user:password@host/dbname") どちらの方法でも、SQLAlchemy で MySQL に接続することができます。 ソース: Bing との会話 2023/6/7 (1) 【Python】SQLAlchemy で MySQL に接続する - Qiita. https://qiita.com/curry__30/items/432a21426c02a68e77e8. (2) SQLAlchemy ORM を使って、Python で MySQL データに連携 …. https://www.cdata.com/jp/kb/tech/mysql-python-sqlalchemy.rst. (3) 【Python】SQLAlchemy を試してみる - Qiita. https://qiita.com/ktamido/items/ebdbe5a85dbc3e6004ae. django .env に django の DATABASE_URL が定義されているとする ...
Sessionのユーザーの取得 Djangoでセッションレコードがどのユーザーのものかを判定するには、以下のようにします。 1 2 3 4 5 6 7 8 from django.contrib.sessions.models import Session from django.contrib.auth.models import User for session in Session.objects.all(): uid = session.get_decoded().get('_auth_user_id') if uid: user = User.objects.get(id=uid) print(user.username) 参考文献: Django ドキュメント | セッションの使いかた ソース: Bing との会話 2023/5/30 (1) セッションの使いかた | Django ドキュメント | Django. https://docs.djangoproject.com/ja//2.2/topics/http/sessions/. (2) 【Django】ログイン判定機能の実装方法を実例付きで徹底解説. https://itc.tokyo/django/dynamic-links-by-user-info/. (3) Djangoで現在ログインしているユーザーのユーザーIDを取得する方法. https://qastack.jp/programming/12615154/how-to-get-the-currently-logged-in-users-user-id-in-django. SessionStoreをつかう 1 2 3 4 5 6 7 from django.contrib.sessions.backends.db import SessionStore key = "3gsbhdfm4g2uyyieaaxl1omor2p5f1on" store = SessionStore(session_key=key) store["ssout_required"] = True store.save()
DRF: Content Negotiation DefaultContentNegotiation content_negotiation_classをカスタマイズするには、以下のようにします。 1 2 3 4 5 6 from rest_framework.negotiation import DefaultContentNegotiation class MyContentNegotiation(DefaultContentNegotiation): def select_renderer(self, request, renderers, format_suffix=None): # ここに処理を書きます。 pass 上記の例では、DefaultContentNegotiationを継承しています。 select_renderer()メソッドには、レンダラーを選択するための処理を書きます。 このメソッドは、リクエストオブジェクト、レンダラーのリスト、およびフォーマットサフィックスを引数として受け取ります。 ソース: Bing との会話 2023/5/12 (1) Content negotiation - Django REST framework. https://www.django-rest-framework.org/api-guide/content-negotiation/. (2) Django REST Framework - Content negotiation - HTTPは …. https://runebook.dev/ja/docs/django_rest_framework/api-guide/content-negotiation/index. (3) Django REST framework カスタマイズ方法 - チュートリアルの補足. https://qiita.com/okoppe8/items/c58bb3faaf26c9e2f27f. ViewSetでの設定 ViewSetごとにcontent_negotiation_classを設定することができます。 ...
pandas: カラム連結 pandasで数値カラム同士を文字列に変換するには、 df['新しい列名'] = df['数値カラム1名'].astype(str) + df['数値カラム2名'].astype(str) と書くことができます。 例えば、以下のようになります。 1 2 3 4 5 import pandas as pd df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}) df['C'] = df['A'].astype(str) + df['B'].astype(str) print(df) 出力: A B C 0 1 3 13 1 2 4 24 以上のように、df['新しい列名'] = df['数値カラム1名'].astype(str) + df['数値カラム2名'].astype(str) を使って、2つの数値の列を文字列に変換してから連結して新しい列を追加することができます。 ソース: Bing との会話 2023/5/11 (1) python - dataframe内の数値から文字列に変換する方法 - スタック …. https://ja.stackoverflow.com/questions/74518/dataframe%e5%86%85%e3%81%ae%e6%95%b0%e5%80%a4%e3%81%8b%e3%82%89%e6%96%87%e5%ad%97%e5%88%97%e3%81%ab%e5%a4%89%e6%8f%9b%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95. (2) 【Pandas】DataFrameから文字列と数値データのcolumnを分ける. https://mochablog.org/pandas-saparate-numerical-col/.