Add-A-New-Column

Wed 11 March 2026

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

Wed 11 March 2026
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

Funcrtions

Wed 11 March 2026
def vowels_present(strx):
    count=0
    for char in strx:
        if char in ("a","e","i","o","u"):
            count = count + 1
    print(count)
    return(strx)

stry = str(input("Enter str: "))
result = vowels_present(stry)
print("the numbers of vowels present is: ",result) 
#problems on args:

def sum_all(*numbers):
    return sum(numbers)
print …

Category: basics

Read More

Looping

Wed 11 March 2026
print("hello world")
hello world
##sum of elements in a user entered list
arr = []
j=0
n = int(input("enter number of elements: "))
for i in range (n):
    elements = int(input("enter element: "))
    arr.append(elements)
print("elements entered are: ",arr)

sum=0
while j <= n:
    sum=sum+arr[i …

Category: basics

Read More
Page 1 of 1