Vikulk
Vikulk

Reputation: 55

Appending excel sheet with dataframe

I have written a code and it is working fine but, i need some help to organize it properly.

Here i am creating an excel sheet and trying to append at the end of the line.

Code:

writer = pd.ExcelWriter('demo.xlsx', engine='xlsxwriter')
df = pd.DataFrame(columns=['DEVICE_ID','DEVICE_NAME','DRIVER_VERSION'])

for key,value in driver_dict.items():
    device = clean_generic_terms(str(key)).lower()
    hwids = all_drivers_details["driverElements"][device]["HardwareID"].split(",")

    df = df.append({'DEVICE_ID': ["NA" if dev_id=='' else dev_id for dev_id in hwids],
                        'DEVICE_NAME': device,
                        'DRIVER_VERSION': value}, ignore_index=True)

    print(df)

df.to_excel(writer, sheet_name='Windows10', index=False)

writer.save()

The current working code is generating excel sheet with the below output.

generated excel sheet

Here i need to separate each device id's by comma and update into separate line. Now code is inserting device id list itself into a single row.

I need something like this

enter image description here

Please help me. Thanks in advance.

Upvotes: 0

Views: 62

Answers (1)

Krk Rama Krishna
Krk Rama Krishna

Reputation: 117

Actually you should post a reproducible code so that we can try and post the answer. Anyway, you give this a shot. Inside your main for loop add this code and try.

hwids = all_drivers_details["driverElements"][device]["HardwareID"].split(",")
for id in hwids
    df = df.append({'DEVICE_ID': "NA" if id=='' else id,
                        'DEVICE_NAME': device,
                        'DRIVER_VERSION': value}, ignore_index=True)

print(df)

Upvotes: 1

Related Questions