Skip to content

Instantly share code, notes, and snippets.

View sainathadapa's full-sized avatar

Sainath Adapa sainathadapa

View GitHub Profile
# On ubuntu, this is needed to compile Cairo:
# sudo apt-get install libcairo2-dev
# sudo apt-get install libxt-dev
# install.packages('Cairo')
library(ggplot2)
# Regular png
png('test1-png.png')
@sainathadapa
sainathadapa / test.Rmd
Created March 23, 2016 11:41
'<!-- -->' in markdown output
---
title: "test"
output:
md_document:
variant: markdown_github
---
```{r pressure, echo=FALSE}
plot(pressure)
```
@sainathadapa
sainathadapa / empty_workspace.json
Created March 29, 2016 05:21
Workaround to have an empty workspace in I3 Window manager
{
"border": "pixel",
"floating": "auto_off",
"layout": "stacked",
"percent": 1,
"type": "con",
"nodes": [
{
"border": "pixel",
"current_border_width": 3,
@sainathadapa
sainathadapa / data.csv
Created April 6, 2016 10:50
ogdindiar-#15
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 7.
"name","link"
"Average Load Of Goods Trains (All Tracation) Broad Gauge and Metre Gauge upto 2013-14","https://data.gov.in/resources/average-load-goods-trains-all-tracation-broad-gauge-and-metre-gauge-upto-2013-14/download"
"Average Number Of Locomotives In Use Daily (Diesel) Narrow Gauge upto 2013-14","https://data.gov.in/resources/average-number-locomotives-use-daily-diesel-narrow-gauge-upto-2013-14/download"
"Average Number Of Locomotives In Use Daily (Electric) Metre Gauge upto 2013-14","https://data.gov.in/resources/average-number-locomotives-use-daily-electric-metre-gauge-upto-2013-14/download"
"Engine Usage - Engine Kilometres Per Day Per Engine In Use Goods upto 2013-14","https://data.gov.in/resources/engine-usage-engine-kilometres-day-engine-use-goods-upto-2013-14/download"
"Average Number Of Locomotives In Use Daily (Diesel) Broad Gauge upto 2013-14","https://data.gov.in/resources/average-number-locomotives-use-daily-diesel-broad-gauge-upto-2013-14/download"
"Average Number Of Locomotives In Use Dai
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,
@sainathadapa
sainathadapa / .gitignore
Created September 1, 2016 11:06 — forked from wzhd/.gitignore
Parsing Evernote export file (.enex) using Python
*.enex
@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 / 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 / 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 / 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):