Python Forum
Want to shorten the python code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Want to shorten the python code
#4
(Apr-24-2022, 06:36 AM)shantanu97 Wrote: I recommend everyone to check attached python script as it will give you an idea how I written my python code and logic.
Ahh what the .... 2238 lines of code 😵
This is not all how you work with Pandas DataFrame.

Clean up data before and when in Pandas work on whole DataFrame with vectorized and build in solutions.
So loop or build in iterrows() should only be used when needed,in most cases not at all.
People think in Python way where loop is common to us,Pandas need a different approach.

Some more info in Optimizing Pandas
Quote:Perhaps the most important rule is to avoid using loops in Pandas code.
Looping over a Series or a DataFrame processes data one item or row/column at a time.
Instead, operations should be vectorized.
This means an operation should be performed on the entire Series or DataFrame row/column.
Developers should think of all operations as matrix computations that can be parallelized
Reply


Messages In This Thread
Want to shorten the python code - by shantanu97 - Apr-24-2022, 06:36 AM
RE: Want to shorten the python code - by deanhystad - Apr-25-2022, 02:38 AM
RE: Want to shorten the python code - by snippsat - Apr-25-2022, 01:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python multiple try except block in my code -- can we shorten code mg24 10 6,510 Nov-10-2022, 12:48 PM
Last Post: DeaD_EyE
  How to shorten the size of program garikhgh0 11 6,300 Feb-22-2018, 06:35 PM
Last Post: snippsat
  How do I shorten my input options? - text adventure ShiningKnight 3 4,743 Jan-01-2017, 03:21 AM
Last Post: ichabod801
  Shorten this List Comprehension ATXpython 7 7,147 Oct-10-2016, 07:50 AM
Last Post: wavic

Forum Jump:

User Panel Messages

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