简体   繁体   English

如何将 Pandas Dataframe 转换为 Numpy 数组

[英]How to convert Pandas Dataframe into Numpy array

In my project of Job-Shop Scheduling, I have to schedule fifty jobs and each job has multiple operations that can be executed on five machines.在我的 Job-Shop Scheduling 项目中,我必须安排 50 个作业,每个作业有多个操作可以在五台机器上执行。 The sample CSV data of the first three jobs are as follow: Sample Dataframe .前三个作业的示例 CSV 数据如下: Sample Dataframe

I wana convert above dataframe into the following numpy array:我想将上面的数据帧转换为以下 numpy 数组:

jobs_data = [  # task = (MC_ID, BURST_Time).
    [(1, 20), (3, 23), (4, 20), (3, 22)],  # JOB_ID = 0
    [(1, 22)],  # JOB_ID = 1
    [(4, 22)],  # JOB_ID = 2
]

I have tried using different functions but failed to get the required results.我曾尝试使用不同的功能,但未能获得所需的结果。

If you are using pandas read_csv to read the file.如果您使用 pandas read_csv 来读取文件。 Then you can convert to a NumPy array.然后您可以转换为 NumPy 数组。 pd.read_csv('<filepath>');

pd.DataFrame(dataframe).to_numpy()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM