Skip to content

Instantly share code, notes, and snippets.

@aurora1625
aurora1625 / pandas_snippets_2.py
Last active January 28, 2021 07:25
pandas snippet 2
# If you want to filter rows by a certain number of columns with null values, you may use this:
df.iloc[df[(df.isnull().sum(axis=1) >= qty_of_nuls)].index]
# update each value in column while iterating over the dataframe row by row
for index_label, row_series in df.iterrows():
# For each row update the 'Bonus' value to it's double
df.at[index_label, 'Bonus'] = row_series['Bonus'] * 2
# select column by multiple range
df_10_2_rank.iloc[:, np.r_[0,16:31]]
@aurora1625
aurora1625 / tfidf_corpus.py
Created January 12, 2021 02:18
extract tfidf keywords from a corpus
## THE CODE IS SELF EXPLANATORY AND COMMENTED
## loading some dependencies
import gensim
from gensim.utils import simple_preprocess
from gensim.parsing.preprocessing import STOPWORDS
from nltk.stem import WordNetLemmatizer, SnowballStemmer
from nltk.stem.porter import *
import nltk
nltk.download('wordnet')
@aurora1625
aurora1625 / zshrc
Created December 15, 2020 08:03
zshrc
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/home/zhibo/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
@aurora1625
aurora1625 / vimrc
Created December 15, 2020 07:55
vimrc
set nocompatible " not vi compatible
syntax on " enable syntax processing
" Spaces & Tabs
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set tabstop=4 " number of visual spaces per TAB
set softtabstop=4 " number of spaces in tab when editing
set shiftwidth=4 " Insert 4 spaces on a tab
set expandtab " tabs are spaces, mainly because of python
@aurora1625
aurora1625 / vim
Created December 8, 2020 01:51
vim #vim
w Go to the beginning of next word
e Go to the end of current word
b Go to the beginning of previous word
0 Go to the starting of current line
$ Go to the end of current line
g_ Go to the last non blank character of current line
H Go to the first line of current screen.
L Go to the last line of current screen
gg Go to the top of the file
@aurora1625
aurora1625 / tabulate.py
Created December 2, 2020 03:59
tabulate #pandas #tabulate
from tabulate import tabulate
print(tabulate(df, tablefmt="plain"))
'''
Supported table formats are:
"plain"
"simple"
"github"
"grid"
@aurora1625
aurora1625 / conda into ipykernel
Last active March 27, 2022 23:22
Conda env into ipykernel #conda
python -m ipykernel install --user --name thisenv
@aurora1625
aurora1625 / check tf cuda.py
Last active March 27, 2022 23:22
Check #tensorflow #CUDA
import tensorflow as tf
print(tf.test.is_built_with_cuda())
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

force the remove of the image even if it is used by containers or having multiple tags

docker rmi -f

# PyTorch device
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
X = torch.randn(n_points, 2).to(device)