Python Programming Python Code Samples



Filters


get sublist or sub matrix of numpy arrays
kishore_kumar | 11 months, 1 week
import numpy as np
random_arr = np.random.randint(1,50,9)
mat1 = ran.reshape(3,3)
python numpy
Get stats ( lines, words, char count ) of file in python
kishore_kumar | 1 year, 1 month
def file_stats(path):
    f = open(path, 'r')
    lines = f.readlines()
python
shuffle two lists and maintain order in python
kishore_kumar | 9 months
import random

fruits = ['apples', 'mangoes', 'grapes', 'oranges']
python random
How to add markers and values to the line plot in python matplotlib
kishore_kumar | 8 months, 3 weeks
import matplotlib.pyplot as plt

t = ['12-03-18','12-04-18' , '12-05-18', '12-06-18', '12-07-18']
python matplotlib
List all files and folders using python os module
kishore_kumar | 1 year, 1 month
import os

def list_files_folders(path):
python python-os
use python requests to get contents of url ( get request )
kishore_kumar | 11 months, 1 week
import requests

req = requests.get("https://httpbin.org/get")
python python-requests
Get os details using python os
kishore_kumar | 1 year, 1 month
import os
print os.uname()
# Don't use os.system('uname -a'), its just executing "uname -a" comman
python python-os
How to connect to presto using python and pyhive
kishore_kumar | 5 months, 4 weeks
from pyhive import presto
cur = presto.connect('presto.yourhost.com',
                     '8889',
python pyhive presto
generate random numbers matrix with numpy python
kishore_kumar | 11 months, 1 week
import numpy as np

random_arr = np.random.randint(1,50,9)
python numpy
gaya38
Shuffle list elements in python
gaya38 | 11 months, 2 weeks
import random;
z = [1,90,4,2]
z = random.shuffle(z)
python
Next