Skip to content

Commit

Permalink
Refactor code to rename 'Br/Ba' column to 'bedrooms_bathrooms'
Browse files Browse the repository at this point in the history
  • Loading branch information
perfectly-preserved-pie committed Sep 2, 2024
1 parent ebe27b4 commit ae726ed
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
Binary file modified assets/datasets/buy.parquet
Binary file not shown.
2 changes: 1 addition & 1 deletion assets/javascript/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ window.dash_props = Object.assign({}, window.dash_props, {
${spaceRentBlock}
<tr>
<th style="text-align:left;padding:8px;border-bottom:1px solid #ddd;">Bedrooms/Bathrooms</th>
<td style="padding:8px;border-bottom:1px solid #ddd;">${data.bedrooms}/${data.bathrooms}</td>
<td style="padding:8px;border-bottom:1px solid #ddd;">${data.bedrooms_bathrooms}</td>
</tr>
<tr>
<th style="text-align:left;padding:8px;border-bottom:1px solid #ddd;">Year Built</th>
Expand Down
5 changes: 4 additions & 1 deletion buy_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@
df['Half Bathrooms'] = (df['Br/Ba'].str.split('/', expand=True)[1]).str.split(',', expand=True)[2]
df['Three Quarter Bathrooms'] = (df['Br/Ba'].str.split('/', expand=True)[1]).str.split(',', expand=True)[3]

# Rename the Br/Ba column to bedrooms_bathrooms
df.rename(columns={'Br/Ba': 'bedrooms_bathrooms'}, inplace=True)

# Convert a few columns into int64
# pd.to_numeric will convert into int64 or float64 automatically, which is cool
# These columns are assumed to have NO MISSING DATA, so we can cast them as int64 instead of floats (ints can't handle NaNs)
Expand All @@ -205,7 +208,7 @@
# Convert date_processed into DateTime
df['date_processed'] = pd.to_datetime(df['date_processed'], errors='coerce', format='%Y-%m-%d')

cols = ['Full Bathrooms', 'Bedrooms', 'year_built', 'Sqft', 'list_price', 'Total Bathrooms', 'space_rent', 'ppsqft', 'hoa_fee']
cols = ['Full Bathrooms', 'Bedrooms', 'year_built', 'Sqft', 'list_price', 'Total Bathrooms', 'space_rent', 'ppsqft', 'hoa_fee', 'bedrooms_bathrooms']
# Convert columns to string type for string operations
df[cols] = df[cols].astype(str)
# Remove commas and other non-numeric characters
Expand Down
2 changes: 1 addition & 1 deletion pages/buy_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def update_map(
lat=row.Latitude,
lon=row.Longitude,
data=dict(
#bedrooms_bathrooms=row['Br/Ba'],
bedrooms_bathrooms=row.bedrooms_bathrooms,
#full_bathrooms=row['Full Bathrooms'],
#half_bathrooms=row['Half Bathrooms'],
#popup_html=row.popup_html,
Expand Down

0 comments on commit ae726ed

Please sign in to comment.