DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
(DATA SCIENCE)
EXPLORATORY DATA ANALYSIS (BDS613B)
Activity Based Learning
NAME: Vijaya Vanditha M
USN :1VE22CD060
Programming Assignment-1
Problem Statement 1:
The factorial of the integer n, written n!, is defined as:
n! = n × (n − 1) × (n − 2) × ⋯ × 3 × 2 × 1
Calculate and print the factorial of a given integer.
For example, if n = 30, we calculate 30 × 29 × 28 × ⋯ × 2 × 1 and get
265252859812191058636308480000000.
Function Description
Complete the extraLongFactorials function in the editor below. It should print the result and
return.
extraLongFactorials has the following parameter(s):
n: an integer
Note: Factorials of n > 20 can’t be stored even in a 64-bit long long variable. Big integers
must be used for such calculations. Languages like Java, Python, Ruby etc. can handle big
integers, but we need to write additional code in C/C++ to handle huge values.
Input Format
Input consists of a single integer n
Constraints
1 ≤ n ≤ 100
Output Format
Print the factorial of n.
Sample Input
25
Sample Output
15511210043330985984000000
Explanation
25! = 25 × 24 × 23 × ⋯ × 3 × 2 × 1
Program:
import math
# Complete the 'extraLongFactorials' function below.
# The function accepts INTEGER n as parameter.
def extraLongFactorials(n):
# Write your code here
result = [Link](n)
print(result)
if __name__ == '__main__':
n = int(input().strip())
extraLongFactorials(n)
Programming Assignment-2
Problem Statement:
a) write a python program names & null values. to create a list which
contains name and null values .Find the length of the names & Lower case
all the letter
b) Create a panda series of names & null values. Find the consonants
present in each name.
c) Create a series with the name & illustrate the various operations that
can be performed on pandor strings
d) Create a program in python for the indicator variable.
e) Create a pandas program and illustrate the various regular expression
which is performed on strings
Algorithm:
a)
Simple Summary of the Algorithm:
• Start with a list of names and some None (null) values.
• Remove all the None values from the list.
• For each remaining name:
Convert the name to lowercase.
Find the length of the name.
• Store and display the lowercase name and its length.
b)
Input: A Pandas Series containing names and null (None or NaN) values.
For each element in the Series:
• Check if the element is null.
If yes, assign a result of None or NaN.
If no, convert the name to lowercase.
• Initialize a counter to 0.
• For each character in the name:
Check if the character is an alphabet letter and not a vowel (a, e, i, o, u).
If it’s a consonant, increment the counter.
• Store the count of consonants for that name.
d)
Start
Import pandas as pd
Create a Series names with name values
Convert names to a DataFrame df
Print original DataFrame
Generate dummy variables using pd.get_dummies(df['Name'], prefix='Name')
Concatenate original df with dummy variables to form result
Print the result DataFrame
End
e)
Start
Import pandas as pd
Create a Series names with name values
Print the original Series
Filter names starting with 'S' using ^S
Filter names ending with 'a' using a$
Filter names containing vowels using [aeiouAEIOU]
Replace vowels with '*' using [Link]()
Extract first 3 letters using ^.{3}
Filter names containing 'sh' (case-insensitive)
Filter names with double letters using (.)\1
End
Program:
a)
people = ["Vanditha", None, "Vasundara", "Bhasker", None, "Vimala", "Vijay", None]
# Step 2: Filter out None values
valid_names = [name for name in people if name is not None]
# Step 3 & 4: Convert names to lowercase and find their lengths
processed_names = [([Link](), len(name)) for name in valid_names]
# Display results
print("Processed names (lowercase, length):")
for name, length in processed_names:
print(f"Name: {name}, Length: {length}")
b)
import pandas as pd
# Step 1: Create a pandas Series with names and None values
names = [Link](["Vanditha", None, "Vasundara", "Bhasker", None, "Vimala", "Vijay", None])
# Step 2: Define a function to count consonants
def count_consonants(name):
if [Link](name):
return None
vowels = "aeiou"
return sum(1 for ch in [Link]() if [Link]() and ch not in vowels)
# Step 3: Apply the function to the Series
consonant_counts = [Link](count_consonants)
# Step 4: Display the results
result = [Link]({
"Name": names,
"Consonant Count": consonant_counts
}) print(result)
c)
import pandas as pd
# Step 1: Create a Pandas Series of names
names = [Link](["Vanditha", "Vasundara", "Bhasker", "Vimala", "Vijay"])
print("Original Names Series:")
print(names)
print("\n")
# Step 2: Apply various string operations
print("Lowercase:")
print([Link]()) # Convert to lowercase
print("\n")
print("Uppercase:")
print([Link]()) # Convert to uppercase
print("\n")
print("Title Case:")
print([Link]()) # Capitalize first letter of each word
print("\n")
print("Length of Each Name:")
print([Link]()) # Length of each string
print("\n")
print("Does the name start with 'A'?")
print([Link]('A')) # Check if name starts with 'A'
print("\n")
print("Does the name contain 'a'?")
print([Link]('a', case=False)) # Check if it contains 'a' (case insensitive)
print("\n")
print("Reverse each name:")
print([Link](lambda x: x[::-1]))
d)
import pandas as pd
names = [Link](['Vanditha', 'Vijaya', 'Vimala', 'Siddhartha'])
df = [Link]({'Name': names})
print("Original Data:")
print(df)
dummies = pd.get_dummies(df['Name'], prefix='Name')
result = [Link]([df, dummies], axis=1)
print("\nData with Indicator Variables:")
print(result)
e)
import pandas as pd
# Sample data
names = [Link](["Sidhu", "Geetha", "Sudhakar", "Siddhartha", "Sudeep", "Rakesh", "Asha"])
print("Original Series:")
print(names)
print("\n1. Names starting with 'S':")
print(names[[Link]('^S')])
print("\n2. Names ending with 'a':")
print(names[[Link]('a$')])
print("\n3. Names containing vowels (a, e, i, o, u):")
print(names[[Link]('[aeiouAEIOU]')])
print("\n4. Replace vowels with '*':")
print([Link]('[aeiouAEIOU]', '*', regex=True))
print("\n5. Extract first 3 letters:")
print([Link](r'(^.{3})'))
print("\n6. Names containing 'sh':")
print(names[[Link]('sh', case=False)])
print("\n7. Names with double letters:")
print(names[[Link](r'(.)\1')])
Results:
a)
b)
c)
d)
e)