Titnaic-Evi

Fri 14 November 2025

# https://github.com/datasciencedojo/datasets/blob/master/titanic.csv
import pandas as pd
!ls ../titanic.csv
../titanic.csv
# Load the dataset
data = pd.read_csv('../titanic.csv')
data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 891 entries, 0 to 890
Data columns (total 12 columns):
 #   Column       Non-Null Count  Dtype  
---  ------       --------------  -----  
 0 …

Category: evidentlyai

Read More

Tokenize Sentence

Fri 14 November 2025

title: "Tokenize Sentences" author: "Raja CSP Raman" date: 2019-05-02 description: "-" type: technical_note draft: false source: https://tedboy.github.io/nlps/gensim_tutorial/tut1.html


from gensim import corpora
documents = [
    "The traditional paradigm just seems safer: be firm and a little distant from your employees", 

"The people who work for you should …

Category: gensim-samples

Read More

Total-Score-Calculator

Fri 14 November 2025

import random
total_score_list = []
for i in range(6):

    current_score = random.randint(0, 6)

    print(f'ball {i}, current score: {current_score}')
    total_score_list.append(current_score)
ball 0, current score: 3
ball 1, current score: 0
ball 2, current score: 5
ball 3, current score: 1
ball 4, current score: 5
ball 5 …

Category: basics

Read More

Translator-Factory-Pattern

Fri 14 November 2025

import pyutil as pyu
pyu.get_local_pyinfo()
'conda env: ml311; pyv: 3.11.10 (main, Oct  3 2024, 07:29:13) [GCC 11.2.0]'
print(pyu.ps2("haystack-ai ollama-haystack python-dotenv"))
haystack-ai==2.8.0
ollama-haystack is not installed in the current environment.
python-dotenv==0.21.0




from abc import ABC …

Category: mythraki

Read More

Treemap-1

Fri 14 November 2025
# http://scipy-cookbook.readthedocs.io/items/Matplotlib_TreeMap.html
# http://hcil.cs.umd.edu/trs/91-03/91-03.html
import pylab
from matplotlib.patches import Rectangle
from functools import reduce

class Treemap:
    def __init__(self, tree, iter_method, size_method, color_method):
        """create a tree map from tree, using itermethod(node) to walk tree,
        size_method(node …

Category: barchart

Read More

Treemap-2

Fri 14 November 2025
import pylab
from matplotlib.patches import Rectangle
from functools import reduce

class Treemap:
    def __init__(self, tree, iter_method, size_method, color_method):
        """create a tree map from tree, using itermethod(node) to walk tree,
        size_method(node) to get object size and color_method(node) to get its
        color"""

        self.ax = pylab.subplot(111 …

Category: barchart

Read More

Treemap-Squarify-1

Fri 14 November 2025

#!pip install squarify
import squarify

# these values define the coordinate system for the returned rectangles
# the values will range from x to x + width and y to y + height
x = 0.
y = 0.
width = 700.
height = 433.

values = [500, 433, 78, 25, 25, 7]

# values must be sorted descending (and …

Category: barchart

Read More

Try-Catch-Custom-Error

Fri 14 November 2025

title: "Try Catch with Custom Error" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false


class NegativeMarksError(Exception):
   pass
def check_marks(mark):
    try:

        if(mark < 0):
            raise NegativeMarksError

        if(mark > 50):
            print('pass')
        else:
            print('fail')
    except ValueError:
        print('ValueError: Some value error')
    except TypeError:
        print('TypeError: Cannot …

Category: basics

Read More

Try-Catch-Raise-Error

Fri 14 November 2025

title: "Try Catch with Raise Error" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false


def check_marks(mark):
    try:

        if(mark < 0):
            raise ValueError

        if(mark > 50):
            print('pass')
        else:
            print('fail')
    except ValueError:
        print('ValueError: Some value error')
    except TypeError:
        print('TypeError: Cannot convert into int')
check_marks …

Category: basics

Read More

Ttl-Cache

Fri 14 November 2025

title: "TTL Cache" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


from cachetools import TTLCache
cache = TTLCache(maxsize=10, ttl=10)
cache['city'] = 'Toronto'
cache['city']
'Toronto'
# Run the cell below after 10 seconds
cache['city']
'Toronto'
# more 
# https://stackoverflow.com/questions/31771286/python-in-memory-cache-with-time-to-live

Score: 5

Category: basics

Read More
Page 139 of 146

« Prev Next »