MySQL BULK INSERT

MySQL バルクインサート MySQL 複数データのバルク INSERT や CSV ファイルから高速インポートする方法 【MySQL】LOAD DATA INFILE するときのファイルの文字コード 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 @main.command() @click.argument("source_file") @click.option("--encoding", "-e", default="cp932") @click.pass_context def data_import(ctx, source_file, encoding): """ import TSV file """ opt = get_model()._meta fields = ",".join([f.name for f in opt.fields if f.name not in ["id"]]) SQL = f""" LOAD DATA LOCAL INFILE '{source_file}' INTO TABLE {opt.db_table} CHARACTER SET {encoding} FIELDS TERMINATED BY '\t' ({fields}) ; """ with connection.cursor() as cursor: cursor.execute(SQL) print(cursor.fetchall()) 重複時に UPDATE する(REPLACE): ...

2023年8月15日 · 2 分

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 分

AWS RDS EBSByteBalance%

EBSByteBalance% AWS: EBS 最適化 RDS インスタンスクラスを使用している場合は、CloudWatch のグラフを使用して IOPS またはスループットのスロットリングがないかを確認します。 バーストキャパシティを備えたインスタンスクラスの場合は、CloudWatch のグラフで EBSIOBalance% および EBSByteBalance% のメトリクスを表示します。 EBSIOBalance% または EBSByteBalance% の常に低い値は、インスタンスレベルで IOPS またはスループットのボトルネックが発生していることを示唆しています。 資料 Amazon RDS インスタンスの IOPS のボトルネックによって引き起こされた Amazon EBS ボリュームのレイテンシーをトラブルシューティングするにはどうすればよいですか?

2023年7月25日 · 1 分

Django Migration: Uniqu Field

Django : マイグレーション: Unique フィールドの追加 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 # Generated by Django 3.2.20 on 2023-07-24 06:36 from django.db import migrations, models def advise_fill_advise_code(apps, schema_editor): """ instance.id => instance.advise_code と初期値にする""" Model = apps.get_model("studies", "Advise") for instance in Model.objects.all(): instance.advise_code = str(instance.id) instance.save() class Migration(migrations.Migration): dependencies = [ ("studies", "0015_auto_20211108_1814"), ] operations = [ migrations.AddField( model_name="advise", name="advise_code", field=models.CharField( # オリジナル: # help_text="(id)", max_length=6, unique=True, verbose_name="Advise Code" # 修正: null=True default=None とする help_text="(id)", max_length=6, null=True, default=None, unique=True, verbose_name="Advise Code" ), preserve_default=False, ), # 追加: advise_code (ユニーク) を設定する migrations.RunPython(inspadvise_fill_advise_code, reverse_code=migrations.RunPython.noop), # 追加: null=True default=None を抜く migrations.AlterField( model_name="advise", name="advise_code", field=models.CharField(help_text="(id)", max_length=6, unique=True, verbose_name="Advise Code"), preserve_default=False, ), ]

2023年7月24日 · 1 分

terraform loop

Terraform ループ Terraform での loop 処理の書き方(for, for_each, count) flatten Function

2023年7月19日 · 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 分

Google Cloud Run

Google Cloud Run Kubernetes から Cloud Run に移行する Google Cloud なんもわからないマンが、Cloud Run の凄さをあれこれ調べてみた AWS App Runner https://aws.amazon.com/jp/apprunner/

2023年7月16日 · 1 分

Managed k8s

Managed k8s Provider Service Product AWS EKS(Elastic Kubernetes Service) GCP GKE(Google Kubernetes Engine) Azure AKS(Azure Kubernetes Service) マネージド Kubernetes とは?EKS・AKS・GKE を比較 AWS EKS vs. ECS AWS 自身が考える ECS と EKS の役割 EKS: EKS : 他のプロバイダー/オンプレミスからの移行 ECS: Kubernetes に比べてはるかに運用がしやすく、低コストで、マルチテナントのプラットフォームとしての効率が非常に高い クラスターの起動を無料で行うことができます

2023年7月16日 · 1 分