Multithreading With Queue In Python 3

Snippet 1 import pandas as pdimport threadingimport timefrom multiprocessing import Queuemy_queue = Queue(maxsize=0)#Let us define our workerdef worker(my_queue): #Add some time to fill up the queue time.sleep(5) while(my_queue.qsize() > 0):      entry = my_queue.get() #Let us define our threads herenum_threads = 10threads = []try:  for i in range(num_threads):      t = threading.Thread(target=worker,args=(my_queue)      t.start()     … Continue reading Multithreading With Queue In Python 3

Sqlalchemy Create Engine

from sqlalchemy import create_engine source engine = create_engine(“sqlite:///hawaii.sqlite”) source engine = create_engine(f’sqlite:///../../../ih_final_project_DB/ih_final_project’) con = engine.connect() nombre_tabla = engine.table_names() source def db_connection(path): engine = create_engine(path) connection = engine.connect() return connection source #endpoint = ‘sqlite:///insiders_db.sqlite’ #local endpoint = ‘sqlite:////Users/Alysson/Documents/Projects/Hotel-Booking-Cancelation/data/hotels.sqlite’ #local db = create_engine(endpoint, poolclass=NullPool) connection = db.connect() source protocol = ‘postgresql’ password=ETL_config.password username=ETL_config.username host = ‘localhost’ port… Continue reading Sqlalchemy Create Engine

Regression Trees

Estimated time needed: 20 minutes In this lab you will learn how to implement regression trees using ScikitLearn. We will show what parameters are important, how to train a regression tree, and finally how to determine our regression trees accuracy. Objectives After completing this lab you will be able to: Train a Regression Tree Evaluate… Continue reading Regression Trees

Slicing In Pandas Code Example

Snippet 1 # Select rows 0, 1, 2 (row 3 is not selected) surveys_df[0:3] Snippet 2 # iloc[row slicing, column slicing] surveys_df.iloc[0:3, 1:4] Copyright © Code Fetcher 2020    

Parallel Inner Products

In [1]: from IPython.parallel import Client, require, interactive In [5]: rc = Client() dv = rc.direct_view() lv = rc.load_balanced_view() In [6]: with dv.sync_imports(): import numpy importing numpy on engine(s) In [7]: mat = numpy.random.random_sample((800, 800)) mat = numpy.asfortranarray(mat) In [8]: def simple_inner(i): column = mat[:, i] # have to use a list comprehension to prevent closure return sum([numpy.inner(column, mat[:, j])… Continue reading Parallel Inner Products

Diagnosing Slow Parallel Inner Products

In [1]: from IPython.parallel import Client, require, interactive In [2]: rc = Client() dv = rc.direct_view() lv = rc.load_balanced_view() In [3]: with dv.sync_imports(): import numpy importing numpy on engine(s) In [4]: mat = numpy.random.random_sample((800, 800)) mat = numpy.asfortranarray(mat) In [5]: def simple_inner(i): column = mat[:, i] # have to use a list comprehension to prevent closure return sum([numpy.inner(column, mat[:, j])… Continue reading Diagnosing Slow Parallel Inner Products

Read Csv Uisng Pandas Code Example

Snippet 1 pd.read_csv(‘data.csv’) # doctest: +SKIP Snippet 2 import pandas as pd df = pd.read_csv (r’Path where the CSV file is storedFile name.csv’) print (df) Snippet 3 you should be in the same dir as .py file df = pd.read_csv(‘your_file_name.csv’) Snippet 4 import pandas as pd #import pandas #syntax: pd.read_csv(‘file_location/file_name.csv’) data = pd.read_csv(‘filelocation/fileName.csv’) #reading data… Continue reading Read Csv Uisng Pandas Code Example

Latihan

Latihan Buatlah variabel dengan nama hobi, yang digunakan untuk menampung input dari user dengan label “Hobi kamu apa? : ” , kemudian Cetaklah dengan label Hobi kamu : {hobi} Buatlah variabel nama, yang digunakan untuk menampung input dari user dengan label “Siapa nama kamu? : ” , misal user mengisikan nama “Romi” maka akan tampil… Continue reading Latihan