Skip to content

Instantly share code, notes, and snippets.

View abbasali-io's full-sized avatar
🎯
Focusing

Abbas Ali abbasali-io

🎯
Focusing
View GitHub Profile
@abbasali-io
abbasali-io / neumorphic_button.dart
Last active June 14, 2021 16:55 — forked from av/main.dart
Flutter Neumorphic Exampls
import 'package:flutter/material.dart';
void main() => runApp(NeumorphicApp());
class NeumorphicApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Neumorphic App',
theme: ThemeData(
@abbasali-io
abbasali-io / dsns_datablog_9.js
Last active February 5, 2020 18:05
Plot the Sq per Price for Kuala Lumpur price
# create price per sqft
df['Price_sqft'] = df['Price'] / df['Built_Size']
# most expensive area by price per sqft
dfc = df.copy(deep=True)
# since we have infinite values in the data, for simplicity sake, we will drop these values
dfc = dfc.replace([np.inf, -np.inf], np.nan).dropna(subset=["Price_sqft"], how="all") # replace infinite values with nan
all_property_price_sqft = dfc.groupby('Location')['Price_sqft'].mean().sort_values(ascending=False)
@abbasali-io
abbasali-io / dsns_datablog_8.js
Created February 5, 2020 17:37
Create the plot showing the distribution of properties by Size in Kuala Lumpur
# highly sqft per area
all_property_sqft = df.groupby('Location')['Built_Size'].mean().sort_values(ascending=False)
bx = all_property_sqft.plot(kind='bar', title="Property Size Distribution in Kuala Lumpur", figsize=(15,10), legend=True, fontsize=10, rot=90)
bx.set_xlabel("Locations", fontsize=10)
bx.set_ylabel("Size", fontsize=10)
plt.show()
@abbasali-io
abbasali-io / dsns_datablog_7.js
Last active February 5, 2020 18:01
Create the Plot showing the distribution of Pricing for Kuala Lumpur properties
# most expensive area in KL by mean pricing
all_property_prices = df.groupby('Location')['Price'].mean().sort_values(ascending=False)
ax = all_property_prices.plot(kind='bar', title="Property Price Distribution in Kuala Lumpur", figsize=(15,10), legend=True, fontsize=10, rot=90)
ax.set_xlabel("Locations", fontsize=10)
ax.set_ylabel("Price", fontsize=10)
plt.show()
# impute the values using KNN
# define the methods
def weighted_hamming(data):
categories_dist = []
for category in data:
X = pd.get_dummies(data[category])
X_mean = X * X.mean()
X_dot = X_mean.dot(X.transpose())
#Clean the Price column by stripping the label & commas
def price_cleanup(price):
if pd.notna(price):
price = price.replace("RM", "")
price = price.replace(",", "")
price = price.strip()
return int(price)
else:
return None
@abbasali-io
abbasali-io / knn_impute.py
Created February 3, 2020 18:30 — forked from YohanObadia/knn_impute.py
Imputation of missing values with knn.
import numpy as np
import pandas as pd
from collections import defaultdict
from scipy.stats import hmean
from scipy.spatial.distance import cdist
from scipy import stats
import numbers
def weighted_hamming(data):
@abbasali-io
abbasali-io / dsns_datablog_4.js
Created February 2, 2020 17:18
Clean the Built_Size column, remove the 'sf. ft.' from the data and along with few other varients of these labels. Also, convert the string into the numeric format for calculations at a later stage
# Convert Built_Size into numeric value
def convert_built_size_numeric(bsize):
try:
if re.search(r"sq\.*\s*ft\.*", bsize) is None:
return None
bsize = bsize.replace(",", "") #remove the commas in price
bsize = bsize.replace("'", "") # remove the ''' symbol in few records
bsize = bsize.replace("sq. ft.", "") # remove the sq. ft. from the records
bsize = bsize.replace("sf", "") # some records are in 'sf' format, clean them
@abbasali-io
abbasali-io / dsns_datablog_3.js
Created February 2, 2020 16:34
Split the Built Up Type & Built Up Area Size into two separate columns, i.e. Built_Type & Built_Size, and show the top 5 rows of the dataframe to view the effect
# define the function to split Size into an array of two differnt values
def split_property_size(size, tp=0):
try:
return size.split(":")[tp].strip()
except AttributeError:
return size
#create a new column with the buildup type
df["Built_Type"] = df['Size'].astype(str).apply(split_property_size, tp=0)
df["Built_Type"].value_counts(dropna=False)
@abbasali-io
abbasali-io / dsns_datablog_2.js
Created February 2, 2020 16:30
Clean Property Types in the Data Frame
def clean_property_types(propType):
# Define the cleaned types without the extra details
cleanTypes = [
'Condominium',
'Serviced Residence',
'Terrace/Link House',
'Bungalow',
'Semi-detached House',
'Apartment',
'Residential Land',