Add-A-New-Column
Add a New Column
data = {
'city' : ['Toronto', 'Montreal', 'Waterloo'],
'points' : [80, 70, 90]
}
{'city': ['Toronto', 'Montreal', 'Waterloo'], 'points': [80, 70, 90]}
|
city |
points |
| 0 |
Toronto |
80 |
| 1 |
Montreal |
70 |
| 2 |
Waterloo |
90 |
df = df.assign(code = [1, 2, 3])
|
city |
points |
code |
| 0 |
Toronto |
80 |
1 |
| 1 |
Montreal |
70 |
2 |
| 2 |
Waterloo |
90 |
3 |
Score: 10
Basic2
n = int(input("Enter a number: "))
sum = 0
for i in range(1, n+1):
sum += i
print("Sum:", sum)
n = int(input("Enter a number: "))
count = 0
while n > 0:
count += 1
n //= 10
print("Digit count:", count)
Enter a number: 4
Digit …
Read More
Basic4
def is_anagram(str1, str2):
return sorted(str1.lower()) == sorted(str2.lower())
print("Anagram" if is_anagram(input("First string: "), input("Second string: ")) else "Not Anagram")
First string: listen
Second string: silent
Anagram
import string
def is_pangram(s):
s = s.lower()
return all(ch in s for ch in string.ascii_lowercase)
print …
Read More
Stagergy 1
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.metrics import classification_report, confusion_matrix
df = pd.read_csv('spam.csv', encoding='latin-1')[['v1', 'v2']]
df.columns = ['label', 'text']
df['label'] = df['label'].map({'ham': 0, 'spam': 1})
X_train, X_test …
Read More
Stragergy3
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self): pass
from abc import ABC, abstractmethod
class Shape(ABC):
def info(self):
print("Shape info")
@abstractmethod
def area(self): pass
from abc import ABC, abstractmethod
class Appliance(ABC):
def plug_in(self):
print("Appliance plugged in")
@abstractmethod
def operate …
Read More