transform() ile eksik değer atama

pandas ile Verimli Kod Yazma

Leonidas Souliotis

PhD Candidate

Eksik değerleri sayma

prior_counts = restaurant.groupby('time')
['total_bill'].count()
missing_counts = restaurant_nan.groupby('time')
['total_bill'].count()
print(prior_counts - missing_counts)
time
Dinner    32
Lunch     13
Name: total_bill, dtype: int64
pandas ile Verimli Kod Yazma

Eksik değer atama

missing_trans = lambda x: x.fillna(x.mean())
restaurant_nan_grouped = restaurant_nan.groupby('time')['total_bill']
restaurant_nan_grouped.transform(missing_trans)
.transform() kullanılarak süre: 0.00368881225586 sn
0    20.676573
1    10.340000
2    21.010000
3    23.680000
4    24.590000
5    25.290000
6    20.676573
Name: total_bill, dtype: float64
pandas ile Verimli Kod Yazma

Yerel yöntemlerle karşılaştırma

start_time = time.time()
mean_din = restaurant_nan.loc[restaurant_nan.time == 
'Dinner']['total_bill'].mean()
mean_lun = restaurant_nan.loc[restaurant_nan.time == 
'Lunch']['total_bill'].mean()

for row in range(len(restaurant_nan)):
    if restaurant_nan.iloc[row]['time'] == 'Dinner':
        restaurant_nan.loc[row, 'total_time'] = mean_din
    else:
        restaurant_nan.loc[row, 'total_time'] = mean_lun
print("Results from the above operation calculated in %s seconds" % (time.time() - start_time))
Yerel Python ile süre: 0.172566890717 sn
Süre farkı: %4.578,115
pandas ile Verimli Kod Yazma

Hadi yapalım!

pandas ile Verimli Kod Yazma

Preparing Video For Download...