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
| class Sample: | |
| def __init__(self, x, t): | |
| self.location = x | |
| self.time = t | |
| def __repr__(self): | |
| return f"Sample({self.location}, {self.time})" | |
| class AlphaBetaFilter: |
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
| class Sample: | |
| def __init__(self, x, t): | |
| self.location = x | |
| self.time = t | |
| def __repr__(self): | |
| return f"Sample({self.location}, {self.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
| import numpy as np | |
| pie_x = np.linspace(0, np.pi * 3, 50) | |
| t_loc = np.sin(pie_x) | |
| error_loc = t_loc * (np.random.randint(950, 1050, 50) / 1000.0) # creates error in data | |
| samples = [Sample(loc, t) for t, loc in enumerate(error_loc)] # create samples list |
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
| tracker = AlphaBetaFilter(samples[0], alpha=0.85, beta=0.5, velocity=0.5) # initiate a tracker | |
| for sample in samples[1:]: | |
| tracker.add_sample(sample) # tracking in "real 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
| import sqlite3 | |
| import pandas as pd | |
| with sqlite3.connect('example.db') as conn: | |
| cursor = conn.cursor() |
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
| fields = "id, street, size, number_of_rooms, parking, price" | |
| query = f"create TABLE HOME_PRICES ({fields})" | |
| cursor.execute(query) |
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
| houses = [ | |
| (1, 'first', 110, 4, 1, 100000), | |
| (2, 'second', 90, 3, 0, 65000), | |
| (3, 'second', 90, 3, 1, 72000) | |
| ] | |
| cursor.executemany('insert into HOME_PRICES values (?, ?, ?, ?, ?, ?)', houses) | |
| #cursor.executemany receives an iterable for multiple executions |
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
| with sqlite3.connect('example.db') as conn: | |
| cursor = conn.cursor() | |
| # Changed inside the Database | |
| conn.commit() |
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
| with sqlite3.connect('example.db') as conn: | |
| df = pd.read_sql("select * from HOME_PRICES", conn) | |
| print(df) |
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
| with sqlite3.connect('example.db') as conn: | |
| # creating a cursor | |
| cursor = conn.cursor() | |
| # reading your own data | |
| df = pd.read_csv("your_csv.csv") | |
| # inserting data | |
| rows = [row for name, row in df.iterrows()] |
OlderNewer