This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nltk | |
#python 3.4.0 | |
#nltk==3.0.4 | |
#numpy==1.10.4 | |
text = """The Buddha, the Godhead, resides quite as comfortably in the circuits of a digital | |
computer or the gears of a cycle transmission as he does at the top of a mountain | |
or in the petals of a flower. To think otherwise is to demean the Buddha...which is | |
to demean oneself.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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(value_list)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For gensim | |
from itertools import groupby | |
import gensim | |
class VectorizedCorpus(object): | |
""" | |
Helper Class for using Sklearn Vectorizers with gensim's LDA model | |
handles transformations between gensim corpus / bow representations and sklearn matrix | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
def df_diff(index_cols, data1, data2, lsuffix='_1'): | |
""" | |
usage: | |
comparisondf= df_diff( ['unique_id','date'], current_df, new_df, lsuffix='_curr') | |
retuns: | |
single dataframe with index_cols on the index, as well as all other variables stacked on the index, and the | |
values in each dataframe along the columns. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def df_to_ddl(df, tablename='test.mytable'): | |
data_dtypes = df.dtypes.reset_index().rename(columns = {'index':'colname',0:'datatype'}) | |
# Map pandas datatypes into SQL | |
data_dtypes['sql_dtype'] = data_dtypes.datatype.astype(str).map( | |
{'object':'varchar(24)', | |
'float64':'float', | |
'int64':'int', | |
'bool':'boolean'} ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Google spreadsheet related. | |
Packages required: oauth2client, google-api-python-client | |
* https://gist.github.com/miohtama/f988a5a83a301dd27469 | |
""" | |
from oauth2client.service_account import ServiceAccountCredentials | |
from apiclient import discovery | |
def get_credentials(scopes: list) -> ServiceAccountCredentials: |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
**Convert .ipynb to Slides** | |
cd "test" | |
ipython nbconvert "test.ipynb" --to slides --reveal-prefix "http://cdn.jsdelivr.net/reveal.js/2.6.2" --post serve --config slides_config.py | |
* To print slides add ?print-pdf at the end of the URL and print | |
**Convert .ipynb to LaTex/PDF** | |
ipython nbconvert MyFirstNotebook.ipynb --to latex --post PDF | |
**Convert .ipynb to HTML** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- show running queries (pre 9.2) | |
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query | |
FROM pg_stat_activity | |
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%' | |
ORDER BY query_start desc; | |
-- show running queries (9.2) | |
SELECT pid, age(query_start, clock_timestamp()), usename, query | |
FROM pg_stat_activity | |
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' |
OlderNewer