This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%timeit | |
| prices = listings['price'].values | |
| nr_reviews = listings['number_of_reviews'].values | |
| availability = listings['availability_365'].values | |
| room_types = listings['room_type'].values | |
| scores = np.zeros(len(listings)) | |
| for i in range(len(listings)): | |
| if availability[i] == 0: | |
| scores[i] = 0 | |
| elif prices[i] > 100: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| room_type_scores = {'Entire home/apt': 1, | |
| 'Private room': 0.7, | |
| 'Shared room': 0.2} | |
| %%timeit | |
| scores = np.zeros(len(listings)) | |
| for i in range(len(listings)): | |
| row = listings.loc[i] | |
| if row['availability_365'] == 0: | |
| scores[i] = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # .iloc[] | |
| %%timeit | |
| norm_prices = np.zeros(len(listings,)) | |
| for i in range(len(listings)): | |
| norm_prices[i] = (listings.iloc[i]['price'] - min_price) / (max_price - min_price) | |
| listings['norm_price'] = norm_prices | |
| # 8.91 s ± 479 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) | |
| # Iterrows() | |
| %%timeit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%timeit | |
| listings['norm_price'] = (listings['price'] - min_price) / (max_price - min_price) | |
| # 1.76 ms ± 107 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%timeit | |
| listings['norm_price'] = listings['price'].map(lambda x: (x - min_price) / (max_price - min_price)) | |
| # 39.8 ms ± 2.33 ms per loop (mean ± std. dev. of 7 runs, 10 loops each) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%timeit | |
| norm_prices = np.zeros(len(listings,)) | |
| for i in range(len(norm_prices)): | |
| norm_prices[i] = (listings.loc[i, 'price'] - min_price) / (max_price - min_price) | |
| listings['norm_price'] = norm_prices | |
| # 408 ms ± 61.2 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%timeit | |
| norm_prices = np.zeros(len(listings,)) | |
| for i, row in listings.iterrows(): | |
| norm_prices[i] = (row['price'] - min_price) / (max_price - min_price) | |
| listings['norm_price'] = norm_prices | |
| # 3.99 s ± 346 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%timeit | |
| norm_prices = np.zeros(len(listings,)) | |
| for i in range(len(listings)): | |
| norm_prices[i] = (listings.iloc[i]['price'] - min_price) / (max_price - min_price) | |
| listings['norm_price'] = norm_prices | |
| # 8.91 s ± 479 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%timeit | |
| reviews_subset = reviews_summary[reviews_summary['listing_id'].isin(listings['listing_id'])] | |
| listings.merge(reviews_subset, on='listing_id') | |
| # 48.7 ms ± 618 µs per loop (mean ± std. dev. of 7 runs, 10 loops each) |
NewerOlder