Selecteer willekeurige rijen

Efficiënte code schrijven met pandas

Leonidas Souliotis

PhD Candidate

Willekeurige rijen sampelen met pandas

start_time = time.time()
poker.sample(100, axis=0)
print("Time using sample: {} sec".format(time.time() - start_time))
Time using sample: 0.000750064849854 sec
Efficiënte code schrijven met pandas

Willekeurige rijen sampelen met numpy

start_time = time.time()
poker.iloc[np.random.randint(low=0, high=poker.shape[0], size=100)]
print("Time using .iloc[]: {} sec".format(time.time() - start_time))
Time using .iloc[]: 0.00103211402893 sec
Verschil in snelheid: 37.6033057849%
Efficiënte code schrijven met pandas

Willekeurige kolommen sampelen

start_time = time.time()
poker.sample(3, axis=1)
print("Time using .sample(): {} sec".format(time.time() - start_time))
Time using .sample(): 0.000683069229126 sec
N = poker.shape[1]
start_time = time.time()
poker.iloc[:,np.random.randint(low=0, high=N, size=3)]
print("Time using .iloc[]: {} sec".format(time.time() - start_time))
ime using .iloc[]: 0.0010929107666 sec
Verschil in snelheid: 59.9999999998%
Efficiënte code schrijven met pandas

Laten we oefenen!

Efficiënte code schrijven met pandas

Preparing Video For Download...