Skip to content

Instantly share code, notes, and snippets.

View kennir's full-sized avatar
🏠
Working from home

Ken Zhang kennir

🏠
Working from home
View GitHub Profile
@kennir
kennir / hide_code.py
Created July 5, 2016 05:46
在iPython Notebook中隐藏代码
from IPython.display import HTML
HTML('''<script>
code_show=true;
function code_toggle() {
if (code_show){
$('div.input').hide();
} else {
$('div.input').show();
}
@kennir
kennir / groupby_multindex.py
Last active July 5, 2016 05:45
Groupby MultiIndex level
In [26]: s
first second third
bar doo one 0.404705
two 0.577046
baz bee one -1.715002
two -1.039268
foo bop one -0.370647
two -1.157892
qux bop one -1.344312
@kennir
kennir / add_new_column.py
Last active July 5, 2016 05:44
Adds a new column where each entry is the list of two other columns
df= pd.DataFrame(np.random.randn(10,4))
df[4]= [[df[2][x],df[3][x]] for x in range(df.shape[0])]
@kennir
kennir / trim.h
Created July 5, 2016 05:34
trim string
// trim from start
static inline std::string &ltrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
return s;
}
// trim from end
static inline std::string &rtrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
return s;