我怎样才能把下面从数值计算中得到的数据分成不同的列呢?
import random
import numpy as np
import pandas as pd
low = 0
high = 500
sample_size = 5
def get_numbers(low, high, sample_size):
return random.sample(range(low, high), sample_size)
p_one = np.array(get_numbers(low, high, sample_size), dtype=int)
p_two = np.array(get_numbers(low, high, sample_size), dtype=int)
p_three = np.array(get_numbers(low, high, sample_size), dtype=int)
p_four = np.array(get_numbers(low, high, sample_size), dtype=int)
p_five = np.array(get_numbers(low, high, sample_size), dtype=int)
c_one = np.array(get_numbers(low, high, sample_size), dtype=int)
c_two = np.array(get_numbers(low, high, sample_size), dtype=int)
c_three = np.array(get_numbers(low, high, sample_size), dtype=int)
c_four = np.array(get_numbers(low, high, sample_size), dtype=int)
c_five = np.array(get_numbers(low, high, sample_size), dtype=int)
for idn in range(0, 10): # ------------------n+1 for the last process step
p = [p_one, p_two, p_three, p_four, p_five]
c = [c_one, c_two, c_three, c_four, c_five]
df_final = pd.DataFrame(
list(
zip(
p,
c,
"storage_workload",
"storage_R1",
"storage_R2",
"storage_R3",
"storage_R4",
"storage_cycle_time",
"storage_n",
"storage_avg_opt_gap",
)
),
columns=[
"Processing",
"Cleaning",
"workload",
"R1",
"R2",
"R3",
"R4",
"Cycle time",
"n",
"Percentage Gap",
],
)
Excel中的预期结果:
谢谢你。
1条答案
按热度按时间uxhixvfz1#
使用您提供的 Dataframe (运行您的代码时所得到的示例):
下面是使用Pandas from_records和MultiIndex.from_product执行此操作的一种方法:
x一个一个一个一个x一个一个二个x