0

I am pretty new to Pandas and was wondering if there was a way that would let me take the data I want and put it in an xlsx file as a table.

This is what I have so far for my code:

import pandas as pd 
import numpy as np
import matplotlib.pyplot as plt
import os
from openpyxl import load_workbook

#defining the excel file and the sheet(s) and printing them
excel_file_1 = 'Incident Report.xls' 
df_first_shift = pd.read_excel(r'C:\Users\M\Downloads\Incident Report.xls') 
print(df_first_shift) 

#combining all the data from the sheets into one file
df_all = pd.concat([df_first_shift]) 

#Creating the .xlsx file 
df_all.to_excel(r'C:\Users\M\OneDrive\Test\Incident_Report.xlsx') 

#Deleting a row
wb = load_workbook(r'C:\Users\M\OneDrive\Test\Incident_Report.xlsx') 
ws = wb['Sheet1']  
ws.delete_cols(1) 
wb.save(r'C:\Users\M\OneDrive\Test\Incident_Report.xlsx') 

1 Answers1

0

If you want to create a new excel every time from a dataframe, pandas has a to_excel function which you should use. If you want to write multiple data frames to an excel this link is helpful.