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 | |
df = pd.DataFrame({'AAA' : [4,5,6,7], 'BBB' : [10,20,30,40],'CCC' : [100,50,-30,-50]}); df | |
''' | |
AAA BBB CCC | |
0 4 10 100 | |
1 5 20 50 | |
2 6 30 -30 | |
3 7 40 -50 | |
''' |
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
dict([[h.partition(':')[0], h.partition(':')[2]] for h in rawheaders.split('\n')]) |
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
if any(bad in name for bad in NOT_ALLOWED): | |
raise ValueError("'name' may not contain any of {}".format(NOT_ALLOWED) | |
if not all(isinstance(val, int) for val in DATA) or len(DATA) !=2: | |
raise ValueError("'DATA' must consist of 2 ints") |
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(valuelist)] |
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 | |
sodium = [ 7.22, 30.07 ] | |
sodium_index = [ '2017-06-01', '2017-06-02' ] | |
potassium = [12.19, 10.07] | |
potassium_index = [ '2017-06-01', '2017-06-02' ] | |
sodium_series = pd.Series(sodium, index=sodium_index) | |
potassium_series = pd.Series(potassium, index=potassium_index) |
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 #this is how I usually import pandas | |
import matplotlib.pyplot as plt | |
names = ['Bob','Jessica','Mary','John','Mel'] | |
births = [968, 155, 77, 578, 973] | |
BabyDataSet = list(zip(names,births)) | |
df = pd.DataFrame(data = BabyDataSet, columns=['Names', 'Births']) | |
# Create graph | |
df['Births'].plot() |
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 | |
import matplotlib.pyplot as plt | |
from numpy import random | |
import os | |
# The inital set of baby names | |
names = ['Bob','Jessica','Mary','John','Mel'] | |
# This will ensure the random samples below can be reproduced. | |
# This means the random samples will always be identical. |
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
class SqliteDB: | |
def __init__(self): | |
self.parent_directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
self.db_path = os.path.join(self.parent_directory, 'db.sqlite3') | |
self.db_connection = sqlite3.connect(self.db_path) | |
self.db_cursor = self.db_connection.cursor() | |
def execute(self, query, args=''): | |
return self.db_cursor.execute(query, args) |
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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
# | |
#author: rex | |
#blog: http://iregex.org | |
#filename trie.py | |
#created: 2010-08-01 20:24 | |
#source uri: http://iregex.org/blog/trie-in-python.html | |
# escape bug fix by fcicq @ 2012.8.19 |
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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Time::Piece; | |
my @events = ( '11/17/1999', '12/6/1999', '12/23/1999', | |
'1/23/2000', '1/13/2000', '2/25/2000', | |
'1/5/2000', '3/18/2000', '4/10/2000', | |
'3/12/2000', '12/31/1999'); |