0

How to speed up python loops?

I need to interact with a list of 5000 items and the loop takes around 5 minutes to cover the list.

23rd Oct 2018, 2:51 PM
Alejandro De Barros
Alejandro De Barros - avatar
4 Respostas
+ 2
can we see your code?
23rd Oct 2018, 7:08 PM
Roneel
Roneel - avatar
+ 2
List comprehesions are a bit faster than loops, maybe try constructing those, instead of using regular loops.
23rd Oct 2018, 7:15 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
0
Without showing your code we can only give you general answers. A thing you should consider is using PYPY which is much faster than CPython as it uses a JIT compiler: https://pypy.org/
23rd Oct 2018, 3:13 PM
TurtleShell
TurtleShell - avatar
0
import pandas as pd data = pd.read(SQL, cnxn) df.pd.DataFrame(data) for i in df: s = df[df['Item'] == i a = s.pivot(index='Item', columns='Date', values='Quantity') I'm making a plot for each item and saving it into an specific folder
23rd Oct 2018, 7:18 PM
Alejandro De Barros
Alejandro De Barros - avatar