Skip to content

Instantly share code, notes, and snippets.

View vikas-git's full-sized avatar

Vikas Shrivastava vikas-git

  • Gurgaon
View GitHub Profile
@vikas-git
vikas-git / boto_script.py
Last active November 25, 2019 05:22
Basic operation to push object on AWS S3
'''
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
@vikas-git
vikas-git / generic_views.txt
Last active October 9, 2019 09:00
Different types of Generic views
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
@vikas-git
vikas-git / only_number.js
Created September 18, 2019 10:47
js code for allow only number in textbox...
$(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;
}
});
@vikas-git
vikas-git / query.txt
Created September 10, 2019 06:01
Some tricks of pandas for working more fast
# 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)
*
@vikas-git
vikas-git / dataframe_queries.txt
Last active September 9, 2019 05:05
In this gist trying to explain how to use sql queries on dataframes.
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
@vikas-git
vikas-git / geovis.py
Created August 13, 2019 10:30
Implement folium library
# -*- 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
"""
@vikas-git
vikas-git / get_lat_long_script.py
Created July 22, 2019 04:55
script for get Lat-Long from Address string
"""
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
@vikas-git
vikas-git / mongo_query.js
Created July 18, 2019 07:51
Some common and important commands for MONGODB
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 ); } );
@vikas-git
vikas-git / csv_to_mongo.py
Created July 16, 2019 07:28
Script for import data from csv to mongo DB using Pandas dataframe
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'
@vikas-git
vikas-git / dataframe_func_query.txt
Last active August 18, 2019 17:53
Important Query for Pandas Dataframe
# 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'))