Skip to content

Instantly share code, notes, and snippets.

View AnnikaNoren's full-sized avatar

Annika Noren AnnikaNoren

View GitHub Profile
View basement_select.py
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']
View basement_where.py
temp['has_basement'] = np.where(temp['calc_basement'] == 0, False, True)
temp.head()
View renovation.py
df['renovation'] = df['yr_renovated'].fillna(pd.Series(np.random.choice([999, 0],
p=[744/17011, 1-(744/17011)],
size=len(df))))
View waterfront_values.py
print("Value counts for waterfront: \n{}".format(df.waterfront.value_counts()))
print("\nTotal waterfront values: {}".format(len(df.waterfront)))
View wrong_drop.py
df.waterfront.dropna(axis=0,inplace=True)
View gist:cc724a377c400b4cd874d1137db6f26d
# 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()
View gist:d90c83cdcf05fa37603db366f8290ecd
# 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])
View gist:231dd4f5fffe7e3d3c6e81a07e1880c5
def split(text):
return [char for char in text]
View gist:f4b8c7788fe871266d98a0312162e462
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:
View bracket_matcher_v1.py
def bracket_matcher(sample):
for char in sample:
if char == ')':
print('True')
else:
print('False')