Skip to content

Instantly share code, notes, and snippets.

View nishitpatel01's full-sized avatar
🎯
Focusing

Nishit nishitpatel01

🎯
Focusing
View GitHub Profile
# List unique values in a DataFrame column
# h/t @makmanalp for the updated syntax!
df['Column Name'].unique()
# Convert Series datatype to numeric (will error if column has non-numeric values)
# h/t @makmanalp
pd.to_numeric(df['Column Name'])
# Convert Series datatype to numeric, changing non-numeric values to NaN
# h/t @makmanalp for the updated syntax!
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 9.
Asset,Type,Asset Value,Debt,Net Value,Change vs 2015,Change,Stake,Latitude,Longitude,Notes
Trump Tower (New York City),Office and retail,471,100,371,-159,Down,1,40.768277,-73.981455,Opened 1983
1290 Avenue of the Americas (New York City),Office and retail,2310,950,408,-62,Down,0.3,40.768277,-73.981455,
Niketown (New York City),Office and retail,400,10,390,-52,Down,1,40.768277,-73.981455,Ground lease through 2079
40 Wall Street (New York City),Office and retail,501,156,345,-28,Down,1,40.768277,-73.981455,
Trump Park Avenue (New York City),Residential and retail,191,14.3,176.7,-27,Down,1,40.768277,-73.981455,"49,564 sq. ft. of condos; 27,467 sq. ft. of retail"
Trump Parc/Trump Parc East (New York City),Residential and retail,88,0,88,17,Up,1,40.768277,-73.981455,"11,750 sq. ft. of condos; 14,963 sq. feet of retail; 13,108 sq. ft. of garage"
"Trump International Hotel and Tower, Central Park West (New York City)","Hotel, condos and retail",38,0,38,21,Up,1,40.768277,-73.981455,
"Trump World Tower, 845 United Natio
@nishitpatel01
nishitpatel01 / train-vertex-ai-automl-image-object-detection-model.ipynb
Last active February 11, 2022 02:21
Train an image object detection model using Vertex AI AutoML (using APIs)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nishitpatel01
nishitpatel01 / create_tsi_dataset.py
Last active August 7, 2022 17:09
Timeseries Insights API - Create Dataset
# TODO - REPLACE WITH SA ACCOUNT KEY
KEY_FILE = '/<path-to-your-service-account-file>/file.json' #REPLACE THIS WITH PROJECT SPECIFIC SERVICE ACCOUNT KEY
ts_endpoint = f'https://timeseriesinsights.googleapis.com/v1/projects/{PROJECT_ID}/datasets'
# Helper function
def query_ts(method, endpoint, data, auth_token):
data = str(data)
headers = {'Content-type': 'application/json', "Authorization": f"Bearer {auth_token}"}
if method == "GET":
@nishitpatel01
nishitpatel01 / list_tsi_datasets.py
Created August 7, 2022 17:18
List all TSI datasets
#list all API datasets
res = query_ts(method="GET", endpoint=ts_endpoint, data=None, auth_token=token)
res
@nishitpatel01
nishitpatel01 / query_tsi_datatset.py
Last active September 20, 2022 18:03
Query TSI dataset for anomaly or forecasting
#create json payload for API query
request_body = {
"detectionTime": "2021-06-27T15:00:00Z",
"slicingParams": {
"dimensionNames": ["measure"]
},
"timeseriesParams": {
"forecastHistory": "259200s",
"granularity": "1800s",
"metric": "temp",
new_event_payload = {
{
"events": [
{
"groupId":"1324354349507023708",
"dimensions":[
{"name":"measure","stringVal":"LTTH"},
{"name":"Humidity","doubleVal":36},
{"name":"Light","doubleVal":99},
{"name":"h2_raw","doubleVal":1041},
delete_ds_endpt = f'https://timeseriesinsights.googleapis.com/v1/projects/{PROJECT_ID}/datasets/{dataset}'
res = query_ts(method="DELETE", endpoint=delete_ds_endpt, data=None, auth_token=token_array[0])
res
@nishitpatel01
nishitpatel01 / evaluate_slice.py
Created October 12, 2022 17:54
evaluateSlice method sample payload
evaluate_slice_payload = {
"detectionTime": "2021-08-09T21:31:54+00:00",
"pinnedDimensions": [
{
"name": "measure",
"stringVal": "LTTH"
}
],
"timeseriesParams": {
"forecastHistory": "259200s",
@nishitpatel01
nishitpatel01 / requirement.txt
Created October 12, 2022 17:56
requirement file for cloud function
google-auth
requests==2.24.0
numpy==1.22.3
oauth2client
google-cloud-bigquery==3.3.1