Add-A-New-Column

Mon 30 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


Advanced Numpy

Mon 30 June 2025
import numpy as np
import pandas as pd
import time
from numpy.linalg import inv, det, eig, norm
arr_1 = np.arange(6).reshape(2, 3)  # 6 is divisible by 2
print(arr_1)
[[0 1 2]
 [3 4 5]]
# Cell 2 – Array Creation
arr_2 = np.arange(2*3).reshape(3, -1 …

Category: basics

Read More

Age-Calculator

Mon 30 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

Amazon Price Tracker

Mon 30 June 2025
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.read_csv(r'C:\Users\HP\Desktop\amazon_products.csv')
df
Product Price Rating Reviews
0 Bluetooth Earphones 1599 …

Category: pandas-work

Read More

Anomaly Detection(Variouscases)

Mon 30 June 2025
import pandas as pd
import numpy as np
df = pd.DataFrame({'value': np.append(np.random.normal(0, 1, 20), [10])})
threshold = 3
anomalies = df[np.abs(df['value']) > threshold]
anomalies
import pandas as pd
import numpy as np
df = pd.DataFrame({'value': np.append(np.random.normal(0, 1 …

Category: pandas-work

Read More

Basics Py

Mon 30 June 2025
# Declare variable
x = 5
# Print variable
print(x)
5
# Update variable
x = 10
# Print new value
print("Updated x:", x)
Updated x: 10
text = "Hello Sara"
print(text)
Hello Sara
print("Length:", len(text))
Length: 10
print("Upper:", text.upper())
Upper: HELLO SARA
print("Replace:", text.replace("Sara", "Queen"))
Replace …

Category: basics

Read More

Bmi Calculator

Mon 30 June 2025
import streamlit as st
st.title("⚖️ BMI Calculator")
2025-06-29 18:18:21.810 WARNING streamlit.runtime.scriptrunner_utils.script_run_context: Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.
2025-06-29 18:18:22.090 
  Warning: to view this Streamlit app on …

Category: basics

Read More

Data Abstraction Operator Overloading

Mon 30 June 2025
# Cell 1 - Data Abstraction Example
class Example1:
    def __init__(self, value):
        self.__value = value

    def get_value(self):
        return self.__value * 1

obj1 = Example1(1)
print(obj1.get_value())
1
# Cell 2 - Data Abstraction Example
class Example2:
    def __init__(self, value):
        self.__value = value

    def get_value(self):
        return self.__value * 2

obj2 …

Category: basics

Read More

Data Aggregation Grouping(Basictestcases)

Mon 30 June 2025
import pandas as pd
df = pd.DataFrame({'group': ['A', 'B', 'A', 'B'], 'value': [1, 2, 3, 2]})
df.groupby('group').agg(['sum', 'mean'])
import pandas as pd
df = pd.DataFrame({'group': ['A', 'B', 'A', 'B'], 'value': [1, 2, 3, 3]})
df.groupby('group').agg(['sum', 'mean'])
import pandas as pd …

Category: pandas-work

Read More

Data Visualization Analytics

Mon 30 June 2025
# Cell 1 - matplotlib

import matplotlib.pyplot as plt
import numpy as np

x_1 = np.linspace(0, 10, 100)
y_1 = np.sin(x_1 + 1)

plt.plot(x_1, y_1)
plt.title("Cell 1 - Matplotlib Sine Plot")
plt.xlabel("X")
plt.ylabel("Sin(X + 1)")
plt.show()

png

# Cell 2 - matplotlib

import matplotlib.pyplot …

Category: basics

Read More
Page 1 of 6

Next »