Instantly share code, notes, and snippets.

# Piyush Guptapiyushg91

• Sort options
Last active Jun 1, 2018
View kenny-test.py
 """ Coding Test: Group all the anagrams into sets """ def get_unique_anagram_key(anagram): anagram = anagram.replace(' ', '') # Get rid of any spaces split_anagram = sorted(list(anagram)) key = ''.join(split_anagram) return key def group_list_by_anagrams(input_list):
Created Apr 7, 2018
this thing
View whatever-again.py
 def get_edge_order(sorted_edges, all_nodes): set_trackers = {node: set(node) for node in all_nodes} edge_order = [] for edge, _ in sorted_edges: node1, node2 = edge[0], edge[1] # Case where the nodes already belong to the same set if set_trackers[node1] == set_trackers[node2]: continue else:
Created Apr 4, 2018
whatevssss
View whatevs.py
 def get_nodes_parent(tree, node_to_evaluate): for i, row in enumerate(tree): if row[node_to_evaluate] == 1: return i else: return None
Created Apr 3, 2018
View whatevs
 def calculate_path_weight(node, seen_nodes, current_weight): # Case when we've seen all the nodes if set(seen_nodes) == set(input_graph.keys()): return current_weight to_return_path_weight = 10000 for path_node, path_weight in input_graph[node]: if path_node not in seen_nodes: new_seen_nodes = seen_nodes + [path_node] total_path_weight = calculate_path_weight(path_node, new_seen_nodes, current_weight + path_weight) if total_path_weight < to_return_path_weight:
Created Mar 23, 2018
stats
View stat.py
 if obs_mean < null_mean: pval = 2 * (null_vals < obs_mean).mean() else: pval = 2 * (null_vals > obs_mean).mean() pval
Last active Feb 2, 2018
View damn_it.py
 from pandas import DataFrame, Series a = [1, 2, 3, 4] b = a.append(5) print(a) # [1, 2, 3, 4, 5] print(b) # None
Created Feb 1, 2018
View bleh
 selk = SelectKBest(k=5) dtc = DecisionTreeClassifier(max_depth=6, random_state=42, min_samples_split=3) pipline_steps = [ ('best_feature', selk), ('decision_tree', dtc) ] clf = Pipeline(pipline_steps)
Created Jan 27, 2018
View data
 /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Applications/PyCharmOld.app/Contents/helpers/pydev/pydevd.py --multiproc --qt-support --client 127.0.0.1 --port 54837 --file /Users/piyushgupta/projects/udacityintroML/final_project/poi_id.py pydev debugger: process 6180 is connecting Connected to pydev debugger (build 143.2371) /Library/Python/2.7/site-packages/sklearn/cross_validation.py:41: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20. "This module will be removed in 0.20.", DeprecationWarning) total number of data points: 146 total number of people in dataset: 146 total number of poi: 18 total number of not poi: 128
Last active Jan 27, 2018
View yield_curve_starter.py
 import sys from datetime import date import quandl '''sys.argv is a module that has all the inputs of a command line in a list so for example if you run python main.py "2018-1-25" sys.argv would be [main.py', '2018-1-25']
Created Jan 23, 2018
View solution.py
 import requests import pandas as pd import matplotlib.pyplot as plt def get_bls_key(): """ This method will get the BLS API key that is expected in api-key.txt file. That file is in the .gitignore and each user should have their own API key
You can’t perform that action at this time.