import pandas as pd
import random
from tkinter import filedialog
def multi_columns(data_frame):
df = data_frame.copy()
if type(df.columns) is not pd.MultiIndex:
return df
# 列にUnnamedという文字の入った内容を削除しインデックスを振り直す
df = df.rename(columns=lambda x: x if not 'Unnamed' in str(x) else '')
df = df.reset_index()
cols = df.columns
copy_col = list(cols)
# column.namesを新しいcolumnの一番上(インデックスセルの一番左)に持ってくる
name_col = tuple([(name if name is not None else '') for name in cols.names])
copy_col[0] = name_col
# 無効セルは上に詰める
for i, col in enumerate(copy_col):
pack = [content for content in col if content != ""]
copy_col[i] = tuple(pack + ([""] * (len(col) - len(pack))))
df.columns = pd.MultiIndex.from_tuples(copy_col)
cols.names = tuple([None for x in cols.names])
return df
# テストパターン読み込み
typ = [('テストパターン(excelファイル)','*.xlsx')]
excel_file_path = filedialog.askopenfilename(filetypes=typ)
df = pd.read_excel(excel_file_path, skiprows=0, header=[0, 1])
t_p = multi_columns(df)
# テストパターン読み出してコマンドを作成
# テストパターンは、0列目:インデックス、1列目:イベント、2列目:引数の数、3列目以降は引数の最小値、最大値2列おきに続く
for i in range(len(t_p)):
eve = t_p.iloc[i]["イベント"]
arg_num = t_p.iloc[i]["引数の数"]
command = eve
#引数の数分だけ引数を結合
for j in range(int(arg_num)):
arg_min = t_p.iloc[i, 3+j*2]#3列目以降2列ごとにデータがある前提
arg_max = t_p.iloc[i, 4+j*2]#4列目以降2列ごとにデータがある前提
command += " " + str(random.randint(arg_min, arg_max))
#キャリッジリターンも結合
command += "\r\n"
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme