Python

とある関係で、マンションの部屋番号を無作為で選択するってコードを書いてる。。 2〜13階で各階 x01〜x06まで部屋がある。例: 11階の04部屋 → 1104。

import numpy as np
import pandas as pd
floor_set = np.arange(2, 14)  # 2から14未満
root_set =  np.arange(1, 4)  # 1から4未満
order_set = np.arange(1, 5) # 1から5未満
order_json = ['A', 'B', 'C', 'D']
order_dict = dict(zip(order_set, order_json))

trial_count = 5
floor_sample = np.random.choice(floor_set, trial_count)  # floor_set から無作為抽出を、trial_count回の結果をnumpy.arrayで。
root_sample = np.random.choice(root_set, trial_count)  # root_set から無作為抽出を、trial_count回の結果をnumpy.arrayで。
order = np.random.choice(order_set, trial_count)  # order_set から無作為抽出を、trial_count回の結果をnumpy.arrayで
df = pd.DataFrame({'階': floor_sample, '番号': root_sample})
df['部屋番号'] = df['階'].map(lambda x : str(x)) + df['番号'].map(lambda x : str(x).zfill(2))
  	階 	番号 	部屋番号
0 	4 	3 	403
1 	10 	3 	1003
2 	11 	1 	1101
3 	7 	2 	702
4 	2 	1 	201

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS