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
test_1 = pd.DataFrame([['Test 1', 'Dogs', 'Cats'], ['Test 2', 'Fogs', 'Squids']], columns=['Company', 'A1', 'A2']) | |
test_2 = pd.DataFrame([['Test 1', 4, 5, 6], ['Test 1', 6,3,1], ['Test 1', 3, 3, 1], ['Test 2', 2,3 ,4], ['Test 2', 7, 8, 9]], columns=['Company', 'V1', 'V2', 'V3']) | |
pd.merge(left=test_2, right=test_1, how='left', left_on='Company', right_on='Company') |
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
from scipy.interpolate import interp1d | |
# params: [from_min, from_max], [to_min, to_max] | |
m = interp1d([1,100],[1,7]) | |
m(99.234) | |
# output: array(6.9535757575757575) |
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
akka.actor{ | |
creation-timeout = 20s | |
default-dispatcher { | |
throughput = 20 | |
executor = "fork-join-executor" | |
fork-join-executor { | |
parallelism-min = 16 | |
parallelism-factor = 2.0 | |
parallelism-max = 16 | |
} |
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 getJDBCResults(sql:String = "SHOW PROCESSLIST()") : List[Map[String,Any]] = { | |
// classOf[com.mysql.jdbc.Driver] | |
val conn = DriverManager.getConnection(s"${this.dsn}?user=${this.dbuser}&password=${this.dbpassword}") | |
try { | |
// Configure to be Read Only | |
val statement = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY) | |
val rs = statement.executeQuery(sql) |
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 urlses(cl: ClassLoader): Array[java.net.URL] = cl match { | |
case null => Array() | |
case u: java.net.URLClassLoader => u.getURLs() ++ urlses(cl.getParent) | |
case _ => urlses(cl.getParent) | |
} | |
val urls = urlses(getClass.getClassLoader) | |
urls.filterNot(_.toString.contains("ivy")).foreach(println) |
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 numpy as np, random, time, random, itertools | |
from itertools import cycle | |
class connect4: | |
# These values will override dynamic class attributes | |
defaults = { | |
'board_matrix_size': (7,6), # Standard connect-4 board size is 7x6 | |
'game_simulate_steps': 3, # For testing | |
'game_simulate_delay': 1, # Delay between game simulation steps |
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
data = [ | |
["2001-10-1", 2, 3, 4], | |
["2001-11-1", 2, 3, 4], | |
["2001-05-1", 2, 3, 4], | |
["2001-05-1", 2, 3, 4], | |
["2001-03-1", 2, 3, 4] | |
] | |
df = pd.DataFrame(data, columns=["date", "a", "b", "c"]) | |
df["my_date"] = pd.to_datetime(df["date"]) | |
df.dtypes |
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 | |
# Careful of displaying too many results in a single browser session == high CPU potential | |
pd.options.display.max_rows = 999 | |
pd.options.display.max_columns = 999 |
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, numpy as np | |
data = [["blabla", "234234234", "yoyoyo", "Super Store235"], | |
[np.nan, np.nan, np.nan, "Super Store"], | |
[np.nan, np.nan, np.nan, "Super Store"], | |
["yo yo yo", 456, 789, "Super Store"], | |
[np.nan, np.nan, np.nan, "Super Store"], | |
[np.nan, np.nan, np.nan, "Super Store"], | |
[123, 456, 789, "Super Store2"], |
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
from sklearn.linear_model import LinearRegression | |
from sklearn.datasets import load_diabetes | |
from sklearn.cross_validation import train_test_split | |
# We load some test data | |
data = load_diabetes() | |
# Put it in a data frame for future reference -- or you work from your own dataframe | |
df = pd.DataFrame(data['data']) |