LoginSignup
0
1

More than 3 years have passed since last update.

よく使うPythonコード 

Last updated at Posted at 2021-02-19

基本的なライブラリ

import cv2
import numpy as np
from matplotlib import pyplot as plt
import pandas as pd

配列変換

#ndarray→list
arr_2d = np.arange(6).reshape((2, 3))
# [[0 1 2]
#  [3 4 5]]
list_2d = arr_2d.tolist()
# [[0, 1, 2], [3, 4, 5]]

#listに変換
test = list(test)

#list→pd
test = pd.Series(test)#1列
test_pd = pd.DataFrame(test)#2列以上

#pd→list
test = test.values.tolist()

データ型変換

#文字列→数字
test = "test"
test2 = float(test)

#数字→文字列
test = 100
test2 = str(test)

CSVファイル系

#csvファイル読み込み
csv = pd.read_csv('csv.csv',header=None)#ファイルの中身そのまま読み込みたい場合

#csv出力
test.to_csv("test.csv",  header=False, index=False)#header, index 指定しない場合

#csvトリミング
test = test.iloc[y_min:y_max,x_min:x_max]

#pd変換
test_pd = pd.DataFrame(test)
result = pd.concat([test_pd1, test_pd2], axis=1)#列を横に連結

#csvデータ名を定義
X=X.rename(columns={0:'X'})
X.to_csv("test.csv")#header, index 指定する場合

リスト

list = []
list.append(test)
0
1
2

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