Python Forum
Moving data from one Excel to another and finding maximum profit
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Moving data from one Excel to another and finding maximum profit
#1
I have the following code: -

import pandas as pd

out = pd.read_excel(io = "E:/Folder/Company Financials.xlsx", sheet_name = "Sales", usecols = "A:J", skiprows = 5)
print(out)
1. How do I change the code so that the data is copied over to a new Excel file but being retained in the original file?
2. How do I find the maximum profit in column H called 'Profit'?

Thanks in advance.
Reply
#2
Do you mean a new sheet?
Reply
#3
Copy and transfer data from the 'Sales' sheet in "E:/Folder/Company Financials.xlsx" and paste it into a separate new Excel file, say "E:/Folder/Company Financials2.xlsx". The sheet name can be 'Sheet1'.
Reply
#4
untested:
import pandas as pd
 

df = pd.read_excel(io = "E:/Folder/Company Financials.xlsx", sheet_name = "Sales", usecols = "A:J", skiprows = 5)
print(df)

with pd.ExcelWriter("E:/Folder/Company Financials2.xlsx") as writer:
    df.to_excel(writer, sheet_name='Sheet1')
Reply
#5
Fantastic, thanks.
Reply
#6
Is there a way to add a header after the new file is created or include it with the data except rows 2-5?
Reply
#7
headers should be added as the new file is being created, as the first record written.
Reply
#8
OK I understand. Will try and see how to do that. You've got me thinking Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy data from Excel and paste into Discord (Midjourney) Joe_Wright 4 1,926 Jun-06-2023, 05:49 PM
Last Post: rajeshgk
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,048 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 1,802 Dec-12-2022, 08:22 PM
Last Post: jh67
  Trying to Get Arduino sensor data over to excel using Python. eh5713 1 1,620 Dec-01-2022, 01:52 PM
Last Post: deanhystad
  Appending a row of data in an MS Excel file azizrasul 3 1,139 Nov-06-2022, 05:17 PM
Last Post: azizrasul
  SMA (simple moving avg) Not receiving Data (stock prices). gdbengo 2 1,408 Jul-31-2022, 08:20 PM
Last Post: paulyan
  get data from excel and find max/min Timmy94 1 1,077 Jul-27-2022, 08:23 AM
Last Post: Larz60+
  How to keep columns header on excel without change after export data to excel file? ahmedbarbary 0 1,130 May-03-2022, 05:46 PM
Last Post: ahmedbarbary
  Need Help writing data into Excel format ajitnayak87 8 2,438 Feb-04-2022, 03:00 AM
Last Post: Jeff_t
Smile Set 'Time' format cell when writing data to excel and not 'custom' limors 3 6,204 Mar-29-2021, 09:36 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020