Vektorizace s poli NumPy pomocí .values()

Psaní efektivního kódu s pandas

Leonidas Souliotis

PhD candidate

NumPy v pandas

df = pd.DataFrame({'Col1':[0, 1, 
2, 3, 4, 5, 6]}, dtype=np.int8)
print(df)
|        | Col1 | 
|--------|------| 
| 0      | 0    | 
| 1      | 1    | 
| 2      | 2    | 
| 3      | 3    | 
| 4      | 4    | 
| 5      | 5    | 
| 6      | 6    |
nd = np.array(range(7))
print(nd)

[0 1 2 3 4 5 6]
Psaní efektivního kódu s pandas

Jak provést vektorizaci pomocí NumPy

start_time = time.time()
poker[['R1', 'R2', 'R3', 'R4', 'R5']].values.sum(axis=1)
print("Time using NumPy vectorization: {} sec(time.time() - start_time))
Results from the above operation calculated in 0.00157618522644 seconds
start_time = time.time()
poker[['R1', 'R2', 'R3', 'R4', 'R5']].sum(axis=1)
print("Results from the above operation calculated in %s seconds" % (time.time() - start_time))
Results from the above operation calculated in 0.00268197059631 seconds
Difference in time: 39.0482%
Psaní efektivního kódu s pandas

Pojďme na to!

Psaní efektivního kódu s pandas

Preparing Video For Download...