0
1

More than 3 years have passed since last update.

CSVをリサイズして返す関数

Last updated at Posted at 2020-06-23

意外と見当たらなかったので作りました。
グレースケール画像のリサイズと同じことしてます

CSVをリサイズして返す関数
from PIL import Image
from glob import glob
import numpy as np
import os

def resize_csv(file, width, height):
    original = np.loadtxt(file, delimiter=",")
    img = Image.fromarray(original)
    resized_img = img.resize((width, height))
    return np.array(resized_img)

def resize_all_csv(folder, width, height):
    files = glob(folder + "*")
    for file in files:
        basename = os.path.basename(file)
        ext = os.path.splitext(basename)[-1]
        if not ext == ".csv":
            continue
        resized = resize_csv(file, width, height)
        np.savetxt(yourefolderandnamehere, resized, delimiter=',')

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1