Skip to content

Instantly share code, notes, and snippets.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tianqig
tianqig / gist:9c207adbf2fc41d643cd381b5468a05b
Created July 22, 2017 06:18 — forked from dmiro/gist:fa05d8337b93532dff36
How to properly use python's isinstance() to check if a variable is a number?
You can use the types module:
>>> import types
>>> var = 1
>>> NumberTypes = (types.IntType, types.LongType, types.FloatType, types.ComplexType)
>>> isinstance(var, NumberTypes)
True
Note the use of a tuple to test against multiple types.
@tianqig
tianqig / useful_pandas_snippets.py
Created July 23, 2017 08:32 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
# List unique values in a DataFrame column
pd.unique(df.column_name.ravel())
# Convert Series datatype to numeric, getting rid of any non-numeric values
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True)
# Grab DataFrame rows where column has certain values
valuelist = ['value1', 'value2', 'value3']
df = df[df.column.isin(valuelist)]
from sklearn.metrics import accuracy_score
import statsmodels.api as sm
logit = sm.Logit(Y_train, X_train)
result = logit.fit()
print(result.summary2())
Y_p = np.zeros((len(Y_test), 1))
p = result.predict(X_test)
Y_p[p > 0.5] = 1.
@tianqig
tianqig / test_plotly.py
Created July 26, 2017 04:18 — forked from rhettallain/test_plotly.py
Here is a python code to make a simple plot in plotly
import plotly
py = plotly.plotly(username='**username**', key='**put your api key here**')
y=0
t=0
dt=0.01
g=9.8
v=4
@tianqig
tianqig / git-syntax-highlighting.sh
Created July 26, 2017 11:19 — forked from sparrow/git-syntax-highlighting.sh
This is a Git command that we used for our blog post https://rubygarage.org/blog/basic-git-commands-you-should-definitely-know at RubyGarage. This Git command allows us to switch on code highlighting for Git outputs.
$ git config --global color.ui true
@tianqig
tianqig / name-and-email-git-configurations.sh
Created July 26, 2017 11:21 — forked from sparrow/name-and-email-git-configurations.sh
These are the Git commands that we used for our blog post https://rubygarage.org/blog/most-basic-git-commands-with-examples at RubyGarage. These Git commands allow us to configure username and email for Git.
$ git config --global user.name "King Kong"
$ git config --global user.email "king-kong@gmail.com"
@tianqig
tianqig / git-configurations-list.sh
Created July 26, 2017 11:22 — forked from sparrow/git-configurations-list.sh
This is a Git command with an output that we used for our blog post https://rubygarage.org/blog/basic-git-commands-you-should-definitely-know at RubyGarage. This Git command allows us to view the list of current Git configurations; the output message lists all configurations.
$ git config --list
user.name=King Kong
user.email=king-kong@gmail.com
@tianqig
tianqig / ipython_notebook_in_git.md
Created July 26, 2017 12:12 — forked from pbugnion/ ipython_notebook_in_git.md
Keeping IPython notebooks under Git version control

This gist lets you keep IPython notebooks in git repositories. It tells git to ignore prompt numbers and program outputs when checking that a file has changed.

To use the script, follow the instructions given in the script's docstring.

For further details, read this blogpost.

The procedure outlined here is inspired by this answer on Stack Overflow.