Ignition K6
Ignition K6

Reputation: 147

python dataframe auto-generate excel sheet

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

Upvotes: 1

Views: 340

Answers (2)

trigonom
trigonom

Reputation: 528

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")

Upvotes: 2

SublimizeD
SublimizeD

Reputation: 134

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)

Upvotes: 1

Related Questions