1

I have a massive data-set that is entirely repetitive and i was thinking the best way to automate the task was with python. This is for an engineering project that uses motors of only 2 types, Follower, or Leader.

For Follower it will have a structure exactly like this(where IFDXXXX is will be the individual drive number):

enter image description here

For a Leader it will have a structure exactly like this(where IFDXXXX is will be the individual drive number):

enter image description here

My idea is that im going to import an excel sheet with the following format and store it as a dataframe with pandas to manipulate later for auto-generation:

enter image description here

Whats the easiest approach to do this, or is there another easier method? I would like to stick with python if possible as im trying to expand my knowledge with this language.

EDIT:

The ultimate end goal is to end up with a sheet that looks something like this:

enter image description here

Update1:

enter image description here

2 Answers 2

2

suppose you have a table like you wanted to save with headlines drive_id and role and they are saved in dataframe df1 to iterate over your lines and create a new table, I prefer doing it with a list of dicts

out_table = []
for index, row in df1.iterrows()
    drive_id = row["drive id"]
    if row["role"]=="follower":
        out_row ={}
        out_row["drive_id"]= drive_id
        out_row["task name"] = "rotate rev"
        out_row["description"] = "check rotate hmi"
        out_row["comment"] = "NA"
        out_table.append(out_row)
#this is the end of the first row, so on you add all the rows for this role
        out_row ={}
        out_row["drive_id"] =  driver_id
        out_row["task name"] = "rotate fwd"
        out_row["description"] = "check hdmi for footlock"
        out_row["comment"] = ""
        out_table.append(out_row)
    if row["role"] == "FOLLOWER"
# here you add all the rows for this role


df2 = pd.DataFrame(out_table)  # this makes a dataframe where the dict keys are the table headers
df2.to_excel(r"D:\drive_table.xlsx")
Sign up to request clarification or add additional context in comments.

2 Comments

do you mean a table to import that looks something like this: Updated original post for clarity
yes, and from it you can generate a new table as said i do it with a list of dicts, then make a dataFrame from it and export it to excel
1
import pandas as pd

df1=pd.read_excel('insert file path here',sheet_name = 0)

this allows pandas to store the excel sheet as a dataframe.

if you want to push a dataframe that is produced after your code you can use

df.to_excel(x)

10 Comments

This is perfect, however how do i format the output to use the structure listed above(follower or leader)?
Can you elaborate on which parameters denote leader and follower
sure. my idea is that im going to import a sheet with pandas that is of the type listed by the 3rd graphic above([IFD#, TYPE]) then store this as a dataframe. I would then like to output either the first or second graphic above, depending on whether or not the IFD is of type Leader or Follower. This will happen for every row in the imported sheet. Updated original post to show what output im trying to achieve
Is it possible for you to update your answer with an example of what you mean? you dont have to for everything, just how i would format say a LEADER drive, then concatenate the dataframe into the ultimate final excel sheet.
Nope. Each IFD is unique and can either be a follower or a leader. As a little backstory, this is from an engineering drawing in CAD that lists what each drive is. There are hundreds. Hence why i wanted to automate the task.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.