This file contains hidden or 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 datetime import datetime | |
| date = '2018-09-13T18:00:00.000Z' | |
| parsed_date = datetime.strptime(time, '%Y-%m-%dT%H:%M:%S.000Z') | |
| print(parsed_date) | |
| # parsed_date is datetime.datetime(2018, 9, 13, 18, 0) |
This file contains hidden or 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 mysql.connector | |
| from openpyxl import Workbook | |
| def main(): | |
| # Connect to DB ----------------------------------------------------------- | |
| db = mysql.connector.connect( user='usr', password='pwd', host='hostip') | |
| cur = db.cursor() | |
| # database name |
This file contains hidden or 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
| #install virtual environment | |
| pip install virtualenv | |
| #Create the virtual environment | |
| virtualenv myenv | |
| #Activate the virtual environment | |
| #On Mac OS / Linux | |
| source myenv/bin/activate |
This file contains hidden or 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 __future__ import print_function | |
| import datetime | |
| from googleapiclient.discovery import build | |
| from httplib2 import Http | |
| from oauth2client import file, client, tools | |
| # If modifying these scopes, delete the file token.json. | |
| SCOPES = 'https://www.googleapis.com/auth/calendar' | |
| def set_event_calender(summary, time): |
This file contains hidden or 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
| grep -rnw '/path/to/somewhere/' -e 'pattern' | |
| -r or -R is recursive, | |
| -n is line number, and | |
| -w stands for match the whole word. | |
| -l (lower-case L) file name of matching files. |
This file contains hidden or 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
| #regex to find url in text | |
| r"(https?:\/\/)(\s)?(www\.)?(\s?)(\w+\.)*([\w\-\s]+\/)*([\w-]+)\/?" |
This file contains hidden or 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
| # importing module | |
| import logging | |
| # Create and configure logger | |
| logging.basicConfig(filename="newfile.log", | |
| format='%(asctime)s - %(levelname)s: %(message)s', | |
| filemode='w') | |
| # Creating an object | |
| logger = logging.getLogger() |
This file contains hidden or 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
| #read csv as data frame | |
| df = pd.read_csv(file_path, header=0) | |
| #write dataframe to csv file | |
| df.to_csv(file_name, sep='\t', encoding='utf-8') | |
| #create zero filled data frame with fixed rows and columns | |
| df_final = pd.DataFrame(0, index=range(5), columns=range(3)) | |
| #insert column in dataframe at fixed index |
This file contains hidden or 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
| # read train data from csv | |
| train = pd.read_csv(file_path, header=0, sep='\t') | |
| # drop identifier columns and convert to np.array | |
| X = np.array(train.drop(['identifier_col'], 1).astype(float)) | |
| y = np.array(train['identifier_col']) | |
| #apply kmeans |
This file contains hidden or 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
| #determine k range | |
| k_range = range(1,6) | |
| #fit the model for each n clusters = k | |
| k_means_var = [KMeans(n_clusters=k).fit(train) for k in k_range] | |
| #pull out the cluster centers for each model | |
| centroids = [V.cluster_centers_ for V in k_means_var] | |
| ## calculate euclidean distance from each point to each cluster center |
OlderNewer