Skip to content

Instantly share code, notes, and snippets.

View arunm8489's full-sized avatar

Arun Mohan arunm8489

View GitHub Profile
price_data = resources.groupby('id').agg({'price':'sum', 'quantity':'sum'}).reset_index()
# join two dataframes in python:
data = pd.merge(data, price_data, on='id', how='left')
data['school_state'] = data['school_state'].str.lower()
print(f'Number of null values:{data["teacher_prefix"].isnull().sum()}')
sns.countplot(data['project_is_approved'])
plt.show()
data["teacher_prefix"] = data["teacher_prefix"].fillna('Mrs.')
data["teacher_prefix"] = data["teacher_prefix"].str.replace('.','')
data["teacher_prefix"] = data["teacher_prefix"].str.lower()
def clean_pro(col):
col = col.str.replace('The', '')
col = col.str.replace(' ','')
col = col.str.replace('&','_')
col = col.str.replace(',','_')
col = col.str.lower()
return col
data['project_subject_subcategories'] = clean_pro(data['project_subject_subcategories'])
data['project_grade_category'] = data['project_grade_category'].str.replace(' ','_')
data['project_grade_category'] = data['project_grade_category'].str.replace('-','_')
data['project_grade_category'] = data['project_grade_category'].str.lower()
data['project_grade_category'].value_counts()
import warnings
warnings.filterwarnings("ignore")
import shutil, time
import torch
from torch.utils.tensorboard import SummaryWriter
import torch.nn.functional as F
import torch.nn as nn
from torch.utils.data import TensorDataset, DataLoader
from collections import Counter,defaultdict
data = pd.read_csv('train.csv')
resources = pd.read_csv('resources.csv')
print(f'Train file shape: {data.shape}')
print(f'Resource file shape: {resources.shape}')
# Utility functions
# function to load the classes
def load_classes(class_file):
fp = open(class_file, "r")
names = fp.read().split("\n")[:-1]
return names
# function converting images from opencv format to torch format
def preprocess_image(img, inp_dim):