Skip to content

Instantly share code, notes, and snippets.

View sainathadapa's full-sized avatar

Sainath Adapa sainathadapa

View GitHub Profile
@sainathadapa
sainathadapa / tensorflow-auc-calculations.ipynb
Created July 4, 2021 14:13
Tensorflow / Keras AUC calculations
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Keybase proof

I hereby claim:

  • I am sainathadapa on github.
  • I am sainatha (https://keybase.io/sainatha) on keybase.
  • I have a public key ASDDFa8dz4QkhONI4YXDMlAASVaQorpwFcrB-uJbq25wwAo

To claim this, I am signing this object:

@sainathadapa
sainathadapa / runner.py
Created September 24, 2018 12:21
Run bunch of commands in parallel, with an option to specify the maximum number of commands to run at a time.
import subprocess
import time
commands_to_run = ['ls -alh' for _ in range(100)]
max_procs = 16
processes = []
while (len(processes) > 0) or (len(commands_to_run) > 0):
if (len(processes) < max_procs) & (len(commands_to_run) > 0):
@sainathadapa
sainathadapa / py-snippet.py
Created July 1, 2018 11:36
Loading Amazon review data into PostgreSQL
import json
def parse(path):
g = open(path, 'r')
for l in g:
yield json.dumps(eval(l), allow_nan=False, ensure_ascii=True)
f = open("kcore_5_strict.json", 'w')
for l in parse("kcore_5.json"):
f.write(l + '\n')
@sainathadapa
sainathadapa / anti_join.py
Created May 9, 2018 10:00
anti-join-pandas
import pandas as pd
def anti_join(x, y, on):
"""Return rows in x which are not present in y"""
ans = pd.merge(left=x, right=y, how='left', indicator=True, on=on)
ans = ans.loc[ans._merge == 'left_only', :].drop(columns='_merge')
return ans
def anti_join_all_cols(x, y):
@sainathadapa
sainathadapa / glimpse.py
Last active December 19, 2023 15:33
glimpse-python
def glimpse(df, maxvals=10, maxlen=110):
print('Shape: ', df.shape)
def pad(y):
max_len = max([len(x) for x in y])
return [x.ljust(max_len) for x in y]
# Column Name
toprnt = pad(df.columns.tolist())
@sainathadapa
sainathadapa / 2017-03-25-ogdindar-presentation.Rmd
Last active July 20, 2020 05:17
Search and Download datasets from data.gov.in
---
title: "Search and Download datasets from data.gov.in"
author: "Sainath Adapa"
date: "25 March 2017"
output:
ioslides_presentation:
highlight: pygments
widescreen: yes
smaller: true
df_print: paged
@sainathadapa
sainathadapa / sankey-code.R
Last active March 18, 2017 04:38
import-export-states-sankey
library(networkD3)
library(magrittr)
library(dplyr)
library(readr)
library(tidyr)
tmp <- read_csv('sankey-data.csv', skip = 2)
tmp <- tmp[-(21:22),]
names(tmp) <- c("X1", "Maharashtra", "Gujarat", "Karnataka", "Andhra Pradesh",
"Uttarakhand", "Rajasthan", "Madhya Pradesh", "West Bengal", "Tamil Nadu",
@sainathadapa
sainathadapa / .gitignore
Created September 1, 2016 11:06 — forked from wzhd/.gitignore
Parsing Evernote export file (.enex) using Python
*.enex
dualplot <- function(x1, y1, y2, x2 = x1,
col = c("#C54E6D", "#009380"),
lwd = c(1, 1), colgrid = NULL,
mar = c(3, 6, 3, 6) + 0.1,
ylab1 = paste(substitute(y1), collapse = ""),
ylab2 = paste(substitute(y2), collapse = ""),
nxbreaks = 5,
yleg1 = paste(gsub("\n$", "", ylab1), "(left axis)"),
yleg2 = paste(ylab2, "(right axis)"),
ylim1 = NULL, ylim2 = NULL, ylim.ref = NULL,