Customer Details: Avinash owns the apartment named “The Sankalp group”, ready to move-in with all comforts. During the registration, he has taken the details from the customer in a distributive manner and now he is finding difficulty to map those details correctly to the corresponding customer.
Akash Avinash’s friend is a Software engineer and is currently working on Data Science. When Avinash approached him with his difficulty, he said it is possible to map the details correctly to the corresponding customer using the functionalities of Data Science.
Luckily, Avinash had stored the details in two different files but in the same order. Where, in one file called “Customer Details” he had stored name, E-mail Id, Phone Number and Age of the customer and in another file, he had stored the street, City state and Pin code of the customers in a file called “Customer Address”.
Let’s us help Akash in writing a code to meet Avinash’s requirements.
Note: Use “prettytable” library to format the output.
Customer Details using Pandas Python
Input Format:
Input consists of an integer indicating the number of customers followed by details of the customer which includes Name, E-mail ID, Phone Number, and Age.
The next set of inputs includes the Street, City, State, Pin code respectively.
The Customer_id and the address_id should be auto-generated.
Output Format:
The output should display all the customer details.
Sample Input -Output1:
3
Customer details
Akshay,akshay@qmphisot.co.in,7760274226,27
Customer address
Vijayanagar,Mysore,Karnataka,570017
Customer details
Krishananand,krishananand@amphisoft.co.in,8192038451,28
Customer address
Ramakrishna Nagar,Mysore,Karnataka,570023
Customer details
Aliya Rehmani,aliya@amphisoft.co.in,9087654321,23
Customer address
Nr Mohalla,Mysore,Karnataka,570029
+—+————-+—————+——————————+————–+—–+————+——————-+——–+———–+———-+
| | Customer_id | Name | Email_Id | Phone_Number | Age | Address_id | Street | City | State | Pin_Code |
+—+————-+—————+——————————+————–+—–+————+——————-+——–+———–+———-+
| 0 | 1 | Akshay | akshay@qmphisot.co.in | 7760274226 | 27 | 1 | Vijayanagar | Mysore | Karnataka | 570017 |
| 1 | 2 | Krishananand | krishananand@amphisoft.co.in | 8192038451 | 28 | 2 | Ramakrishna Nagar | Mysore | Karnataka | 570023 |
| 2 | 3 | Aliya Rehmani | aliya@amphisoft.co.in | 9087654321 | 23 | 3 | Nr Mohalla | Mysore | Karnataka | 570029 |
+—+————-+—————+——————————+————–+—–+————+——————-+——–+———–+———-+
Sample Input -Output2: Input: 0 +--+-------------+------+----------+--------------+-----+------------+--------+------+-------+----------+ | | Customer_id | Name | Email_Id | Phone_Number | Age | Address_id | Street | City | State | Pin_Code | +--+-------------+------+----------+--------------+-----+------------+--------+------+-------+----------+ +--+-------------+------+----------+--------------+-----+------------+--------+------+-------+----------+
Additional Sample TestCases
Sample Input and Output 1 :
3 Customer details Akshay,akshay@qmphisot.co.in,7760274226,27 Customer address Vijayanagar,Mysore,Karnataka,570017 Customer details Krishananand,krishananand@amphisoft.co.in,8192038451,28 Customer address Ramakrishna Nagar,Mysore,Karnataka,570023 Customer details Aliya Rehmani,aliya@amphisoft.co.in,9087654321,23 Customer address Nr Mohalla,Mysore,Karnataka,570029 +---+-------------+---------------+------------------------------+--------------+-----+------------+-------------------+--------+-----------+----------+ | | Customer_id | Name | Email_Id | Phone_Number | Age | Address_id | Street | City | State | Pin_Code | +---+-------------+---------------+------------------------------+--------------+-----+------------+-------------------+--------+-----------+----------+ | 0 | 1 | Akshay | akshay@qmphisot.co.in | 7760274226 | 27 | 1 | Vijayanagar | Mysore | Karnataka | 570017 | | 1 | 2 | Krishananand | krishananand@amphisoft.co.in | 8192038451 | 28 | 2 | Ramakrishna Nagar | Mysore | Karnataka | 570023 | | 2 | 3 | Aliya Rehmani | aliya@amphisoft.co.in | 9087654321 | 23 | 3 | Nr Mohalla | Mysore | Karnataka | 570029 | +---+-------------+---------------+------------------------------+--------------+-----+------------+-------------------+--------+-----------+----------+
Solution:
import pandas as pd
from tabulate import tabulate as tb
n = int(input())
df = pd.DataFrame(columns=['Name', 'Email_Id', 'Phone_Number', 'Age'])
df1 = pd.DataFrame(columns=['Street', 'City', 'State', 'Pin_Code'])
if n <=0:
print("+--+-------------+------+----------+--------------+-----+------------+--------+------+-------+----------+")
print("| | Customer_id | Name | Email_Id | Phone_Number | Age | Address_id | Street | City | State | Pin_Code |")
print("+--+-------------+------+----------+--------------+-----+------------+--------+------+-------+----------+")
print("+--+-------------+------+----------+--------------+-----+------------+--------+------+-------+----------+")
else:
for i in range(n):
print("Customer details")
df.loc[i] = input().split(',')
print("Customer address")
df1.loc[i] = input().split(',')
df['Customer_id'] = df.index + 1
df1['Address_id'] = df1.index + 1
df = df.join(df1)
print(tb(df[['Customer_id', 'Name', 'Email_Id', 'Phone_Number', 'Age', 'Address_id', 'Street', 'City', 'State', 'Pin_Code']],headers='keys', tablefmt='pretty'))
Happy Learning – If you require any further information, feel free to contact me.