Python Code Samples



Filters


conditional selection with numpy arrays
kishore_kumar | 6 years, 12 months
import numpy as np
ser_arr = np.arange(1,10)
mat1 = ser_arr.reshape(3,3)
numpy python
durga
Finding Character in a String python
durga | 6 years, 2 months
S1=raw_input("enter String")
S2=raw_input("enter character")
S1=S1.upper() #we are changing into u
We can use lower() also, But both the strings should be changed into the same case(upper/lower).
python string in operator
Draw subplots in matplotlib
harika | 6 years, 7 months
import matplotlib.pyplot as plt
plt.figure(1)
plt.subplot(211)
You can see the output in the attached image. If you want to play with plot then set specific prope
python matplotlib
Create a dataframe in pandas with dictionary
harika | 6 years, 7 months
import pandas as pd
name_dataset = pd.DataFrame({
    "city": ["Bangalore", "Hyderabad", "Chennai"
python pandas
Create a dataframe in pandas with lists
harika | 6 years, 7 months
import pandas as pd
data = [['Alex',10],['Bob',12],['Clarke',13]]
df = pd.DataFrame(data,columns=[
python pandas list
convert string to python datetime object
kishore_kumar | 6 years, 1 month
import datetime

st = "2019-08-19 05:40"
python datetime
get date ctime from python datetime
kishore_kumar | 6 years, 2 months
import datetime

today = datetime.date.today()
python datetime
Using python generator for finding factors
kishore_kumar | 6 years, 1 month
def get_factors(num):
    i = 1
    while i * i < num:
python generator factors
How to get number of queries executed in Django orm
kishore_kumar | 5 years, 11 months
from django.db import connection

tasks = Task.objects.all()
python django django-orm
Generate Pie Chart in python using matplotlib
kishore_kumar | 6 years, 10 months
import matplotlib.pyplot as plt

labels = 'Grapes', 'Oranges', 'Mangoes', 'Apples'
python matplotlib
Prev Next