This file contains 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
''' | |
For more information visit official documents | |
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-examples.html | |
''' | |
import boto3 | |
from botocore.errorfactory import ClientError | |
from boto3.s3.transfer import S3Transfer | |
This file contains 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
LIST VIEW: | |
from django.views.generic import ListView | |
** Simple example | |
class UsersListView(ListView): | |
model = User | |
** You can add attributes to change the default behaviour. | |
class UsersListView(ListView): | |
model = User |
This file contains 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
$(document).on('keypress', '.only-numbers', function(e){ | |
var keycode = (e.which) ? e.which : e.keyCode; | |
if (!(keycode==8 || keycode == 46)&&(keycode < 48 || keycode > 57)){ | |
return false; | |
} | |
}); |
This file contains 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
# source: https://towardsdatascience.com/10-python-pandas-tricks-that-make-your-work-more-efficient-2e8e483808ba | |
pd.read_csv('file_name.csv', nrows = 5, usecols=['c1', 'c2'], dtype = {‘c1’: str, ‘c2’: int, …}) | |
argument | |
* nrows = 5 (it will select only 5 rows from dataframe) | |
* usecols (select certain columns on df creation) | |
* dtype (specify col data type) | |
* |
This file contains 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
Source Blog: https://medium.com/jbennetcodes/how-to-rewrite-your-sql-queries-in-pandas-and-more-149d341fc53e?source=search_post---------0 | |
-> Sql queries vs pandas queries | |
* select Query | |
-> select * from airports; | |
-> airports.head() | |
* select query with limit | |
-> select * from airports limit 3 |
This file contains 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
# -*- coding: utf-8 -*- | |
""" | |
Created on Tuesday 23-July-2019 | |
@author: Vikas shrivastava | |
For more info go to official documentation of folium https://python-visualization.github.io/folium/modules.html | |
""" |
This file contains 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
""" | |
Python script for batch geocoding of addresses using the Google Geocoding API. | |
This script allows for massive lists of addresses to be geocoded for free by pausing when the | |
geocoder hits the free rate limit set by Google (2500 per day). If you have an API key for paid | |
geocoding from Google, set it in the API key section. | |
Addresses for geocoding can be specified in a list of strings "addresses". In this script, addresses | |
come from a csv file with a column "Address". Adjust the code to your own requirements as needed. | |
After every 500 successul geocode operations, a temporary file with results is recorded in case of | |
script failure / loss of connection later. | |
Addresses and data are held in memory, so this script may need to be adjusted to process files line |
This file contains 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
For Dump and Restore : | |
mongodump --db=<old_db_name> --collection=<collection_name> --out=data/ | |
mongorestore --db=<new_db_name> --collection=<collection_name> data/<db_name>/<collection_name>.bson | |
Loop on mongodb query: | |
db.users.find().forEach( function(myDoc) { print( "user: " + myDoc.name ); } ); |
This file contains 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 os | |
import json | |
import pandas as pd | |
import pymongo | |
def import_content(filepath): | |
mng_client = pymongo.MongoClient('localhost', 27017) | |
mng_db = mng_client['route_planning'] | |
collection_name = 'lat_long' |
This file contains 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
# search with and/or condition | |
df4 = df3.query('(From=="AHH" & To=="BBH") | (From=="BBH" & To=="AHH")') | |
OR | |
data.loc[(data["Gender"]=="Female") & (data["Education"]=="Not Graduate") & (data["Loan_Status"]=="Y"), ["Gender","Education","Loan_Status"]] | |
# Rows to columns | |
df = df.stack().reset_index().rename(columns={'level_0':'From','level_1':'To', 0:'Hours'}) | |
# Join two df like sql join | |
df1 = df1.merge(record_df, on='location_code', how='outer', suffixes=('_x', '_y')) |