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
Py10
# Program 24: Reverse String
def main():
text = input("Enter string: ")
print("Original:", text)
rev = text[::-1]
print("Reversed:", rev)
main()
Enter string: rollex
Original: rollex
Reversed: xellor
# Program 25: Palindrome String
def main():
text = input("Enter string: ")
rev = text[::-1]
if text == rev:
print("Palindrome")
else:
print("Not Palindrome")
main …
Read More
Py11
# Program 27: Count Words
def main():
text = input("Enter sentence: ")
words = text.split()
count = 0
for w in words:
count += 1
print("Total words:", count)
main()
Enter sentence: rubesh
Total words: 1
# Program 28: Largest in List
def main():
nums = list(map(int, input("Enter numbers: ").split()))
largest = nums[0 …
Read More
Py12
# Program 30: Sum of List
def main():
nums = list(map(int, input("Enter numbers: ").split()))
total = 0
for n in nums:
total = total + n
print("Sum is:", total)
main()
Enter numbers: 12
Sum is: 12
# Program 31: Average
def main():
nums = list(map(int, input("Enter numbers: ").split()))
total = 0 …
Read More
Py14
# Program 36: Sort List
def main():
nums = list(map(int, input("Enter numbers: ").split()))
nums.sort()
print("Sorted:", nums)
main()
Enter numbers: 67 89 7 8 8 9
Sorted: [7, 8, 8, 9, 67, 89]
# Program 37: Second Largest
def main():
nums = list(map(int, input("Enter numbers: ").split()))
nums …
Read More
Py16
# Program 42: Access Value
def main():
data = {"a": 10, "b": 20}
key = input("Enter key: ")
if key in data:
print("Value:", data[key])
else:
print("Key not found")
main()
Enter key: 8 9 8 9 7 6
Key not found
# Program 43: Update Dictionary
def main():
data = {"a": 10, "b …
Read More
Py17
# Program 45: Dictionary Length
def main():
data = {"a": 1, "b": 2, "c": 3}
count = 0
for k in data:
count += 1
print("Length:", count)
main()
# Program 46: Loop Dictionary
def main():
data = {"a": 10, "b": 20}
print("Items:")
for k in data:
print(k, data[k])
main()
Read More