Add-A-New-Column

Tue 24 June 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

Tue 24 June 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

Datastructure

Tue 24 June 2025
#list
fruits = ["apple", "banana", "cherry"]
print(fruits[1]) 
banana
#array
import array
nums = array.array('i', [1, 2, 3, 4])  
print(nums[2])  
3
#hash map
student = {"name": "Ravi", "age": 20, "grade": "A"}
print(student["age"])  
20
#dictionary
student = {"name": "Ravi", "age": 20, "grade": "A"}
print(student["age"]) 
20
#tuple …

Category: basics

Read More

Datatypes

Tue 24 June 2025
# Integer
age = 25
print(age)

# Float
height = 5.9
print(height)

# String
name = "Ananya"
print(name)

# Boolean
is_student = True
print(is_student)
# List
fruits = ["apple", "banana", "cherry"]

# Tuple
coordinates = (10.0, 20.0)
print(coordinates)

# Dictionary
student = {"name": "Ananya", "age": 25, "grade": "A"}
print(student)

# Set
unique_numbers = {1, 2, 3, 2 …

Category: basics

Read More

Forloop

Tue 24 June 2025
for i in range(1,11):
    if (i % 2 == 0):
        print(f"{i} even")
    else:
        print(f"{i} odd")
1 odd
2 even
3 odd
4 even
5 odd
6 even
7 odd
8 even
9 odd
10 even


Score: 0

Category: basics

Read More

Leetcode1

Tue 24 June 2025
class solution:
    def twosum(self, num: list[int], target: int) ->list[int]:
        num_dict={}
        for i, num in enumerate{nums}:

Score: 0

Category: basics

Read More

Whileloops

Tue 24 June 2025
count = 1
while count <= 5:
    print("Count is:", count)
    count += 1
Count is: 1
Count is: 2
Count is: 3
Count is: 4
Count is: 5
number = 1
total = 0

while number <= 50:
    if number % 2 != 0:
        number += 1
        continue  # skip odd numbers
    total += number
    number += 1

print("Sum of …

Category: basics

Read More
Page 1 of 1