Add-A-New-Column

Sat 28 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

Sat 28 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

Test 1

Sat 28 June 2025
pip install matplotlib
Requirement already satisfied: matplotlib in c:\users\sanjay\miniconda3\envs\py312\lib\site-packages (3.10.3)
Requirement already satisfied: contourpy>=1.0.1 in c:\users\sanjay\miniconda3\envs\py312\lib\site-packages (from matplotlib) (1.3.2)
Requirement already satisfied: cycler>=0.10 in c …

Category: basics

Read More

Test 2

Sat 28 June 2025
pip install pandas
Collecting pandas
  Downloading pandas-2.3.0-cp312-cp312-win_amd64.whl.metadata (19 kB)
Requirement already satisfied: numpy>=1.26.0 in c:\users\sanjay\miniconda3\envs\py312\lib\site-packages (from pandas) (2.3.1)
Requirement already satisfied: python-dateutil>=2.8.2 in c …

Category: pandas-work

Read More
Page 1 of 1