Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
General Python code for Newbie
#1
My question here:
Hi all, i am new to the python scripting language. I have a requirement that to compare the two excel files. 
Requirement is: Many excel files are downloaded everyday. we have to compare the today's excel file with yesterday's excel file. 
and the difference should be highlighted as red and Exclamatory mark. Can anybody help me. This task is going to decide my job. please help me. Thank you all.
Q1. How can i get the two exact same files today's and yesterday's excel file.
Q2. How to compare the two excels.
Q3. How can i highlight in red and exclamatory mark.
Reply
#2
(Apr-26-2017, 05:34 AM)Ramakrishna Wrote: My question here:
Hi all, i am new to the python scripting language. I have a requirement that to compare the two excel files. 
Requirement is: Many excel files are downloaded everyday. we have to compare the today's excel file with yesterday's excel file. 
and the difference should be highlighted as red and Exclamatory mark. Can anybody help me. This task is going to decide my job. please help me. Thank you all.
Q1. How can i get the two exact same files today's and yesterday's excel file.
Q2. How to compare the two excels.
Q3. How can i highlight in red and exclamatory mark.
How "new" to python are you? This is not really basic I don't think? I would read the files into separate lists, todaysList[ ] and yesterdaysList[ ],  then iterate every item in yesterdaysList[ ] in comparison to todaysList[ ]. As far as highlighting the differences. I'm a newbie to python as well so this is all the info I could give you... lol. Did you want direction or someone to actually write the code for you to use? I guess I should learn how to work with spreed sheets huh lmao
Reply
#3
OS? There are good comparison tools coming with almost every Linux installation.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#4
So, first of all, no one on this forum is going to do this for you. We can help, a lot, but you must show effort and ask specific questions when you hit a problem you can not solve yourself.
Second, this is way too broad questions and we can give only general directions how to start and what you can explore

(Apr-26-2017, 05:34 AM)Ramakrishna Wrote: Q1. How can i get the two exact same files today's and yesterday's excel file.
check Requests if you download the files from Internet
eventually you may need additional packages like Selenium and PhantomJS

if you "download' the files from some network location build-in modules for file manipulation should do.

(Apr-26-2017, 05:34 AM)Ramakrishna Wrote: Q2. How to compare the two excels.
Q3. How can i highlight in red and exclamatory mark.

check packages that allow you to read/write excel files. Is it really xls/xlsx/xlsm files or csv?

http://www.python-excel.org/
https://www.xlwings.org/
build-in csv module (if not really xls* files)

also pandas and numpy are very powerful and have great functionality for data crunching.
Reply
#5
Thank you Low_ki_. At last i found some one responding. Actually they want to screw up from my job. So they gave this task. 3 days back gave the task and every one hour they are asking updates. From last 3 days i am seeing python PyCharm. Can any one have code , plz help me for this time. Thank you in advance..
Reply
#6
(Apr-26-2017, 06:21 AM)Ramakrishna Wrote: Thank you Low_ki_. At last i found some one responding. Actually they want to screw up from my job. So they gave this task. 3 days back gave the task and every one hour they are asking updates. From last 3 days i am seeing python PyCharm. Can any one have code , plz help me for this time. Thank you in advance..

That's not going to work. Even if someone decides to do this for you, after that they will have higher expectations and next assignment will be even more difficult/complex.
one more bit of advise - PyCharm is nice IDE, but it has learning curve too. Given that you are under pressure to deliver result, I would use sumple IDE.text-processing program (e.g. notepadd++ under Win or Atom under Linux, just an example - something simple that would allow you to focus on the task, not on the IDE).
Reply
#7
Q1. You'll need to find a pattern in file names to decide which files you need to compare
Q2. As others have said there are a couple ways to compare Excel files using Python
Q3. AFAIK the exclamation part can only be done using pywin32 to access the Excel COM server

So I would approach the task like this:
1. Determine all file pairs you need to compare for differences
2. Use pywin32 to open both files
3. Compare the files sheet by sheet, cell by cell
4. For each cell in today's file with a different value add the exclamation mark

This task is not too complicated, but it requires some knowledge of Python file system manipulation facilities and Excel COM API so if you are a Python beginner you'll need to do a fair amount of research
Reply
#8
(Apr-26-2017, 08:09 PM)joe_anonimist Wrote: Excel COM API so if you are a Python beginner you'll need to do a fair amount of research

I believe there's a package openpyxl for working with Excels; not a bad one - I've been using it for couple of weeks, though not heavily. Why use something obscure?
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#9
Openpyxl is not able to add annotations to Excel cells (afaik). Excel COM API is not obscure it is the official Microsoft Excel automation API
Reply
#10
Quote:So they gave this task.

If (for real) someone did that to me, I'd quit within the next hour,
or perhaps not show up for a few days like in the movie 'Office Space'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Newbie Needs Help with Python Port to Web RobertL 1 2,171 May-09-2020, 10:50 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