Skip to content

Instantly share code, notes, and snippets.

View AnnikaNoren's full-sized avatar

Annika Noren AnnikaNoren

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