简体   繁体   中英

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. The sample CSV data of the first three jobs are as follow: Sample Dataframe .

I wana convert above dataframe into the following numpy array:

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. Then you can convert to a NumPy array. pd.read_csv('<filepath>');

pd.DataFrame(dataframe).to_numpy()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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