Python Forum
Editing excel documents
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Editing excel documents
#1
Hi all (if the following thread doesn't comply with the rules let me know and I am happy to change it),

I'm currently tasked with analysing some school rankings in excel, using python. In order to carry this out, I would like to go through an excel document that contains the following three columns: 'School Name'; 'County'; 'Number of Pupils'. One of the things I would like to do is create a script that automatically pulls out the 'School Name' for schools with, for example, between 50 and 100 pupils and that are in South Yorkshire, Hampshire, Gloucester or Cumbria and write the results to a txt file with each school name on a separate line, for instance:

Highfield Grammar
Burdy State School
Linkley School
Gamingun Comprehensive... etc. (random names chosen)

I am very much a beginner in python and i understand how to use if, elif, else commands and also point to directories/sources, etc. but haven't yet had much contact with integrating excel. Also, in the effort of learning, please could somebody first reccommend a package/tutorial (I've tried looking on both pyexcel/pandas but couldn't find a tutorial for a problem similar to my own (There may be one, I just haven't found one)) so I can, at least initially, have a go at writing the code myself!

Thank you Smile

P.S. Side question... would it be computationally easier to 1) go through the excel document line by line and append a txt document with the 'School Name' if the criteria fit... or 2) go through the excel document line by line, deleting rows that don't fit the criteria then at the end convert the column of 'School Name' from entry A2 downwards into a txt file?

P.P.S. The file format is '.xlsx'
Reply
#2
first learn pandas: https://pandas.pydata.org/
or
openpyxl: https://openpyxl.readthedocs.io/en/stable/

pandas preferred
the rest will become clear.

Quote:P.S. Side question... would it be computationally easier to 1) go through the excel document line by line and append a txt document with the 'School Name' if the criteria fit... or 2) go through the excel document line by line, deleting rows that don't fit the criteria then at the end convert the column of 'School Name' from entry A2 downwards into a txt file?

Neither:
read the document with Pandas and create report.
Original excel document is not altered.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  A program for backing up documents (doesnt work(code is inside)) Richard_SS 4 3,429 Jun-05-2019, 03:47 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

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