This file contains 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
conditions = [ | |
(temp['calc_basement'] == 0), | |
(temp['calc_basement'] > 0) & (temp['calc_basement'] <= 300), | |
(temp['calc_basement'] > 300) & (temp['calc_basement'] <= 600), | |
(temp['calc_basement'] > 600) & (temp['calc_basement'] <= 1000), | |
(temp['calc_basement'] > 1000) & (temp['calc_basement'] <= 5000), | |
] | |
values = ['level_1', 'level_2', 'level_3', 'level_4','level_5'] | |
This file contains 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
temp['has_basement'] = np.where(temp['calc_basement'] == 0, False, True) | |
temp.head() |
This file contains 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
df['renovation'] = df['yr_renovated'].fillna(pd.Series(np.random.choice([999, 0], | |
p=[744/17011, 1-(744/17011)], | |
size=len(df)))) | |
This file contains 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
print("Value counts for waterfront: \n{}".format(df.waterfront.value_counts())) | |
print("\nTotal waterfront values: {}".format(len(df.waterfront))) |
This file contains 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
df.waterfront.dropna(axis=0,inplace=True) |
This file contains 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
# Create df with zip code as index and mean latitude value for each zip code | |
no_index_zip_lat = df.groupby('zipcode', as_index=True)['lat'].mean() | |
# Convert the data frame to a dict, the zip is the key and mean latitude is the value | |
zip_lat_dict = no_index_zip_lat.to_dict() |
This file contains 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
# This combines the two operations: find digits in the string and find the two numbers that equal 10 | |
def sum_finder(test): | |
target = 10 | |
success = [] | |
result = [int(i) for i in test if i.isdigit()] | |
for i in range(0, len(result)-1): | |
num_sum = (result[i] + result[i+1]) |
This file contains 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
def split(text): | |
return [char for char in text] |
This file contains 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
def char_test(sample): | |
# Call function to see if there are two numbers that add to 10 in the text string | |
success = sum_finder(sample) | |
# Check to see if success (the return is empty or not) | |
if not success: | |
print("False") | |
else: |
This file contains 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
def bracket_matcher(sample): | |
for char in sample: | |
if char == ')': | |
print('True') | |
else: | |
print('False') |
OlderNewer