Skip to content

Instantly share code, notes, and snippets.

View fabsta's full-sized avatar

Fabian Schreiber fabsta

View GitHub Profile
@fabsta
fabsta / perl.snippets
Created February 2, 2013 11:51
Perl code snippets for vim
# #!/usr/bin/perl
snippet #!
#!/usr/bin/perl
# Hash Pointer
snippet .
=>
# Function
snippet sub
sub ${1:function_name} {
@fabsta
fabsta / index.html
Last active December 21, 2015 15:59
<!DOCTYPE html>
<meta charset="utf-8">
<title>Hive Plots</title>
<style>
@import url(../style.css?20120427);
.axis {
stroke: #000;
stroke-width: 1.5px;
@fabsta
fabsta / index.html
Last active December 21, 2015 15:59
Species Tree View
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Gene tree</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<link href="../libs/css/tipsy.css" rel="stylesheet" type="text/css" />
<!-- <link href="../libs/css/control_panel.css" rel="stylesheet" type="text/css" /> -->
@fabsta
fabsta / Readme.md
Last active December 22, 2015 22:09
TreeFam gene tree widget

Readme file for the TreeFam gene tree widget

[TOC]

Apply function to column

df['TitleLength'] = df.Title.apply(len)

df.columns = map(str.lower, df.columns) # lowercase function to column
### single
Y = data['TV'] # column
Y = data.TV
df[:2] # first two rows
df.ix['Maricopa'] # view a row
df.ix[:, 'coverage'] # view a column
df.ix['Yuma', 'coverage'] # view the value based on a row and column
@fabsta
fabsta / 1. data import export (python data science).md
Last active November 21, 2017 18:05
#DataScience #InputOutput

[TOC]

Read

csv

import pandas as pd
[TOC]
# numerical value
age_mean = df['Age'].mean()
df['Age'] = df['Age'].fillna(age_mean)
# categorical value
from scipy.stats import mode
mode_embarked = mode(df['Embarked'])[0][0]

[TOC]

Selecting

Cells

Y = data['TV'] # column
Y = data.TV
df.ix['Arizona', 2]  # Select the third cell in the row named Arizona

[TOC]

New dataframe

First Column as data frame

as.data.frame( df[,1], drop=false)

mydata$newvar <- oldvar