MySQL: 𠮷(つちよし)

MySQL: 𠮷(つちよし) データベース/テーブル utf8mb4にすること 1 ALTER TABLE customers_customer CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; 確認: $ echo "show variables like 'character%';" | python manage.py dbshell Variable_name Value character_set_client utf8mb4 character_set_connection utf8mb4 character_set_database utf8mb4 character_set_filesystem binary character_set_results utf8mb4 character_set_server utf8mb4 character_set_system utf8mb3 character_sets_dir /rdsdbbin/mysql-8.0.28.R4/share/charsets/ character_set_system utf8mb3 が問題 接続 を utf8mb4 にすること django: OPTIONS/charset=utf8mb4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 In [1]: from django.conf import settings In [2]: settings.DATABASES Out[2]: {'default': {'ENGINE': 'django.db.backends.mysql', 'HOST': 'prod-db-instance.xxxxxxxx.ap-northeast-1.rds.amazonaws.com', 'NAME': 'coresys_masters', 'USER': 'coresys_masters', 'PASSWORD': 'va0Gaighoo3Paez8', 'OPTIONS': {'charset': 'utf8mb4', 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"}, 'ATOMIC_REQUESTS': False, 'AUTOCOMMIT': True, 'CONN_MAX_AGE': 0, 'TIME_ZONE': None, 'PORT': '', 'TEST': {'CHARSET': None, 'COLLATION': None, 'MIGRATE': True, 'MIRROR': None, 'NAME': None}}}

2023年10月1日 · 1 分

pandas memo

pandas: Dataframe pandas で特定の文字列を含む行を抽出(完全一致、部分一致) 複数条件: &, | 否定: ~ (NOT) 型変換 Python: pandas でカラムの型を変換する 検索 選択肢: .isin(list) 1 2 result = df[df["code"].isin(["0", "1"])] # 0,1 のみ result = df[~(df["code"].isin(["0", "1"]))] # 0, 1以外 ユニーク unique: 1 items = df["code"].unique() 重複を除外(drop_duplicates): 1 result = df[["code", "name"]].drop_duplicates() 重複を抽出: 1 2 3 4 size = df.groupby(keys).size() res = size[ size > 1 ] if res.shape[0] > 0: print(res) 変換 dict 一覧: ...

2023年8月2日 · 2 分

ruff

ruff 新しい静的コード解析ツール「Ruff」をご紹介 Ruff の紹介 Python の Ruff (linter) でコード整形もできるようになりました Python の Linter Formatter は、もう Ruff 一択。最短 5 分でプロジェクトに導入 1 2 poetry run ruff format . poetry run ruff check . --fix

2023年8月1日 · 1 分

Pandas Sort

Pandas: ソート Find the unique values in a column and then sort them pandas unique values multiple columns NumPy 配列 ndarray を一次元化(平坦化)する ravel と flatten

2023年7月31日 · 1 分

poetry version requirements

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 拡張

2023年7月17日 · 1 分

redis

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: ...

2023年7月14日 · 1 分

Celery AWS ECS

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 標準出力: ...

2023年7月13日 · 1 分

ltsv

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 ¹. ...

2023年6月16日 · 1 分

ndjson

ndjson https://github.com/rhgrant10/ndjson Snowflake: CREATE FILE FORMAT 【Python】Python ~ ndjson を扱う ~ tablib は ndjson をサポートしていない pandas は ndjson を読み込める

2023年6月14日 · 1 分

pandas MySQL

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 が定義されているとする ...

2023年6月7日 · 1 分