Experiment 5 To 8
Experiment 5 To 8
Write a python program to concatenate the data frames with two different objects
Coding:
import pandas as pd
import numpy as np
df2 = pd.DataFrame(np.random.randint(25, size=(6, 4)), index=["5", "6", "7", "8", "9", "10"],
columns=["A", "B", "C", "D"])
6. Write a Python program to check that a string contains only a certain set of characters (in this case
a-z, A-Z and 0-9). Go tothe editor
Coding:
import re
def is_allowed_specific_char(string):
charRe = re.compile(r'[^a-zA-Z0-9]')
string = charRe.search(string)
print(is_allowed_specific_char("ABCDEFabcdef123450"))
print(is_allowed_specific_char("*&%@#!}{"))
Code:
import re
def validate_email(email):
if re.match(r"[^@]+@[^@]+\.[^@]+", email):
return True
return False
email = "[email protected]"
if validate_email(email):
print("Valid email address")
else:
print("Invalid email address")
8. Build a name directory using decorators for a given piece of information about N
people where every person’sname has first and last name, age, and sex. Sort their
ages in ascending order and print their names accordingly. So, the name of the
youngest person should be printed first. If there are two people of the same age,
then you print them in the order of their input.
Code:
def sort_age(func):
def inner(persons):
persons = sorted(persons, key = lambda x: x[1])
return [func(name, sex) for (name, age, sex) in persons]
return inner
@sort_age
def list_name(name, sex):
title = {"M": "Mr. ", "F": "Ms. "}
return title[sex] + name
if __name__ == "__main__":
persons = []
for i in range(input()):
data = raw_input().split()
name, age, sex = data[0] + ' ' + data[1], int(data[2]), data[3]
persons.append([name, age, sex])
print('\n'.join(list_name(persons))