Add-A-New-Column

Mon 21 July 2025

Add a New Column

import pandas as pd
data = {
    'city' : ['Toronto', 'Montreal', 'Waterloo'],
    'points' : [80, 70, 90]
}
data
{'city': ['Toronto', 'Montreal', 'Waterloo'], 'points': [80, 70, 90]}
type(data)
dict
df = pd.DataFrame(data)
df
city points
0 Toronto 80
1 Montreal 70
2 Waterloo 90
df = df.assign(code = [1, 2, 3])
df
city points code
0 Toronto 80 1
1 Montreal 70 2
2 Waterloo 90 3


Score: 10

Category: pandas-work


Age-Calculator

Mon 21 July 2025
from datetime import datetime
def get_age(d):
    d1 = datetime.now()
    months = (d1.year - d.year) * 12 + d1.month - d.month

    year = int(months / 12)
    return year
age = get_age(datetime(1991, 1, 1))
age
33


Score: 5

Category: basics

Read More

Arr

Mon 21 July 2025
arr = list(range(80))
sum_arr = sum(arr)
print('Sum of array with 80 elements:', sum_arr)
arr = list(range(79))
sum_arr = sum(arr)
print('Sum of array with 80 elements:', sum_arr)
arr = list(range(78))
sum_arr = sum(arr)
print('Sum of array with 80 elements:', sum_arr)
arr = list(range(77))
sum_arr …

Category: basics

Read More

Basics

Mon 21 July 2025
# Cell 1
a = 10
# Cell 2
b = 20
# Cell 3
c = a + b
print(c)
# Cell 4
for i in range(5):
    print(i)
# Cell 5
def square(x):
    return x * x
class Person:
    pass
p1 = Person()
print(type(p1))
<class '__main__.Person'>
class Student:
    def __init__(self, name, age …

Category: basics

Read More

Days Conversion

Mon 21 July 2025
# created :20250629
# own code
days = int(input("Enter number of days: "))
years = days // 365
weeks = (days % 365) // 7
remaining_days = (days % 365) % 7

print("Years:", years)
print("Weeks:", weeks)
print("Days:", remaining_days)

Score: 0

Category: basics

Read More

Dsa

Mon 21 July 2025
print("📘 Data Structures and Algorithms (DSA) in Python - 200 Cells")
arr = [3, 1, 4, 1, 5, 9, 2, 6, 5]
print('Original array:', arr)
def bubble_sort(arr):
    n = len(arr)
    for i in range(n):
        for j in range(0, n-i-1):
            if arr[j] > arr[j+1]:
                arr …

Category: basics

Read More

Factorial

Mon 21 July 2025
# created :20250629
# own code
num = int(input("Enter a number: "))
fact = 1
for i in range(1, num + 1):
    fact *= i
print("Factorial of", num, "is", fact)
print("fact"

Score: 5

Category: basics

Read More

Forloop

Mon 21 July 2025
# Step 1: Import time for delay demo
import time
print("📘 Welcome to the Square Generator")
# Step 4: Start loop
for i in range(1, 11):
    # Loop Step 1
    print(f"🔁 Looping... i = {i}")
    # Pause for visibility
    time.sleep(0.2)
    # Calculate square
    square = i ** 2
    # Print square
    print(f"🔢 Square …

Category: basics

Read More

Hcf

Mon 21 July 2025
# created :20250629
https://share.google/camtfs4z8aiYAJNSz
def compute_hcf(x, y):
    if x > y:
        smaller = y
    else:
        smaller = x
for i in range(1, smaller+1):
        if((x % i == 0) and (y % i == 0)):
            hcf = i 
    return hcf
num1 = 54 
num2 = 24
print("The H.C.F. is", compute_hcf(num1, num2 …

Category: basics

Read More

Ifelse

Mon 21 July 2025
a = 40
b = 30
if a > b:
    print('a is greater')
elif a == b:
    print('a is equal to b')
else:
    print('b is greater')
a = 40
b = 30
if a > b:
    print('a is greater')
elif a == b:
    print('a is equal to b')
else:
    print('b is greater …

Category: basics

Read More
Page 1 of 3

Next »