Event Management using Pandas Python

Event Management using Pandas: Sunil the event manager found that using some functionalities of Data science, it was possible to generate the descriptive statistics, the transpose of the data set also to sort the data set according to a particular column or value.
 
He provides his requirement to the development team. Now you being the part of the team, this requirement is assigned to you.
 
Write a code to describe, transpose and sort the data set.

Event Management using Pandas

Input Format:
The input consists of a CSV file containing the data set of 10 rows and 10 columns followed by the choice (1/2/3/4) entered by the user.
 
The choice 1 corresponds to describe the ‘NoOfDates’,’Expected Audience’,’HallPricePerDay’,’TotalCost’ columns  in the dataset.
The choice 2 corresponds to transpose the data set.
The choice 3 corresponds to sort the data set by axis(or 1).
The choice 4 corresponds to sort the data set by value.
 
Output format:
The output displays the data set after altering it according to the choice entered by the user.
 
Sample Input -Output 1:
1)Description

2)Transpose the data

3)Sort by axis

4)Sort by Value

Enter your choice
4

Enter the column name
EventName

+----+---------+------------------------+----------------+-------------+-------------+------------+---------------------+-------------------------+--------------------------------------------------+-------------------+-------------+
|    |   Sl_No | EventName              | EventManager   |   NoOfDates | StartDate   | EndDate    |   Expected Audience | HallName                | HallAddress                                      |   HallPricePerDay |   TotalCost |
|----+---------+------------------------+----------------+-------------+-------------+------------+---------------------+-------------------------+--------------------------------------------------+-------------------+-------------|
|  1 |       2 | Birthday Celebration   | Akshay         |           1 | 14-08-2005  | 14-08-2005 |                 nan | Akshayalaya             | Akshayalaya, Akshaya Dama,Yogendra Nagar,Shimoga |             35000 |       35000 |
|  8 |       9 | Birthday Celebration   | Akshay         |           1 | 14-08-2005  | 14-08-2005 |               10000 | Akshayalaya             | Akshayalaya, Akshaya Dama,Yogendra Nagar,Shimoga |             35000 |       35000 |
|  6 |       7 | Chrismas Celebration   | Collin         |           2 | 24-12-2005  | 25-12-2005 |                1500 | Saint Philominas chruch | Mysore                                           |             25000 |       50000 |
|  2 |       3 | House Warming          | sunil          |           1 | 21-10-2005  | 21-10-2005 |                1000 | Sugamya Corner          | sugamya corner ,Vijaya nagar,Mysore              |             50000 |       50000 |
| 10 |      11 | Marraige               | krishnanand    |           1 | 15-08-2005  | 16-08-2005 |               25000 | krishna mansion         | Krishna Mansion ,Krishnalaya,Shringeri           |             60000 |       60000 |
|  3 |       4 | Naming Ceremony        | Surya          |           1 | 10-11-2005  | 10-11-2005 |                1500 | Suryodaya comforts      | Suryodaya comforts,Srirampura                    |             20000 |       20000 |
|  5 |       6 | New Year Celebration   | Chandan v      |         nan | 31-12-2005  | 01-12-2005 |                 700 | Chinnaswammy stadium    | Bangalore                                        |             12000 |       24000 |
|  7 |       8 | Project outing         | Yaradru        |           2 | nan         | 30-11-2005 |                  25 | Lalth Mahal Palace      | Mysore                                           |             15000 |       30000 |
|  4 |       5 | Promossion Celebration | Aliya          |           1 | 15-11-2005  | 15-11-2005 |                 250 | Kabule convention hall  | Nr Mohalla,Mysore                                |             20000 |       20000 |
|  9 |      10 | Reception              | krishnanand    |           2 | 12-08-2005  | 13-08-2005 |               25000 | krishna mansion         | Krishna Mansion ,Krishnalaya,Shringeri           |             60000 |      120000 |
|  0 |       1 | nan                    | krishnanand    |           2 | 12-08-2005  | 13-08-2005 |               20000 | krishna mansion         | Krishna Mansion ,Krishnalaya,Shringeri           |             60000 |      120000 |
+----+---------+------------------------+----------------+-------------+-------------+------------+---------------------+-------------------------+--------------------------------------------------+-------------------+-------------+

Sample Input – Output 2:

1)Description

2)Transpose the data

3)Sort by axis

4)Sort by Value

Enter your choice
3
Enter the axis to be sorted
1

 +----+------------+----------------+------------------------+---------------------+--------------------------------------------------+-------------------------+-------------------+-------------+---------+-------------+-------------+
| | EndDate | EventManager | EventName | Expected Audience | HallAddress | HallName | HallPricePerDay | NoOfDates | Sl_No | StartDate | TotalCost |
|----+------------+----------------+------------------------+---------------------+--------------------------------------------------+-------------------------+-------------------+-------------+---------+-------------+-------------|
| 0 | 13-08-2005 | krishnanand | nan | 20000 | Krishna Mansion ,Krishnalaya,Shringeri | krishna mansion | 60000 | 2 | 1 | 12-08-2005 | 120000 |
| 1 | 14-08-2005 | Akshay | Birthday Celebration | nan | Akshayalaya, Akshaya Dama,Yogendra Nagar,Shimoga | Akshayalaya | 35000 | 1 | 2 | 14-08-2005 | 35000 |
| 2 | 21-10-2005 | sunil | House Warming | 1000 | sugamya corner ,Vijaya nagar,Mysore | Sugamya Corner | 50000 | 1 | 3 | 21-10-2005 | 50000 |
| 3 | 10-11-2005 | Surya | Naming Ceremony | 1500 | Suryodaya comforts,Srirampura | Suryodaya comforts | 20000 | 1 | 4 | 10-11-2005 | 20000 |
| 4 | 15-11-2005 | Aliya | Promossion Celebration | 250 | Nr Mohalla,Mysore | Kabule convention hall | 20000 | 1 | 5 | 15-11-2005 | 20000 |
| 5 | 01-12-2005 | Chandan v | New Year Celebration | 700 | Bangalore | Chinnaswammy stadium | 12000 | nan | 6 | 31-12-2005 | 24000 |
| 6 | 25-12-2005 | Collin | Chrismas Celebration | 1500 | Mysore | Saint Philominas chruch | 25000 | 2 | 7 | 24-12-2005 | 50000 |
| 7 | 30-11-2005 | Yaradru | Project outing | 25 | Mysore | Lalth Mahal Palace | 15000 | 2 | 8 | nan | 30000 |
| 8 | 14-08-2005 | Akshay | Birthday Celebration | 10000 | Akshayalaya, Akshaya Dama,Yogendra Nagar,Shimoga | Akshayalaya | 35000 | 1 | 9 | 14-08-2005 | 35000 |
| 9 | 13-08-2005 | krishnanand | Reception | 25000 | Krishna Mansion ,Krishnalaya,Shringeri | krishna mansion | 60000 | 2 | 10 | 12-08-2005 | 120000 |
| 10 | 16-08-2005 | krishnanand | Marraige | 25000 | Krishna Mansion ,Krishnalaya,Shringeri | krishna mansion | 60000 | 1 | 11 | 15-08-2005 | 60000 |
+----+------------+----------------+------------------------+---------------------+--------------------------------------------------+-------------------------+-------------------+-------------+---------+-------------+-------------+
Sl_No,EventName,EventManager,NoOfDates,StartDate,EndDate,Expected Audience,HallName,HallAddress,HallPricePerDay,TotalCost
1,,krishnanand,2,12-08-2005,13-08-2005,20000,krishna mansion,"Krishna Mansion ,Krishnalaya,Shringeri",60000,120000
2,Birthday Celebration,Akshay,1,14-08-2005,14-08-2005,,Akshayalaya,"Akshayalaya, Akshaya Dama,Yogendra Nagar,Shimoga",35000,35000
3,House Warming,sunil,1,21-10-2005,21-10-2005,1000,Sugamya Corner,"sugamya corner ,Vijaya nagar,Mysore",50000,50000
4,Naming Ceremony,Surya,1,10-11-2005,10-11-2005,1500,Suryodaya comforts,"Suryodaya comforts,Srirampura",20000,20000
5,Promossion Celebration,Aliya,1,15-11-2005,15-11-2005,250,Kabule convention hall,"Nr Mohalla,Mysore",20000,20000
6,New Year Celebration,Chandan v           ,,31-12-2005,01-12-2005,700,Chinnaswammy stadium,Bangalore,12000,24000
7,Chrismas Celebration,Collin,2,24-12-2005,25-12-2005,1500,Saint Philominas chruch,Mysore,25000,50000
8,Project outing,Yaradru,2,,30-11-2005,25,Lalth Mahal Palace,Mysore,15000,30000
9,Birthday Celebration,Akshay,1,14-08-2005,14-08-2005,10000,Akshayalaya,"Akshayalaya, Akshaya Dama,Yogendra Nagar,Shimoga",35000,35000
10,Reception,krishnanand,2,12-08-2005,13-08-2005,25000,krishna mansion,"Krishna Mansion ,Krishnalaya,Shringeri",60000,120000
11,Marraige,krishnanand,1,15-08-2005,16-08-2005,25000,krishna mansion,"Krishna Mansion ,Krishnalaya,Shringeri",60000,60000

Solution:

import pandas as pd
from tabulate import tabulate as tb

df = pd.read_csv('Event_Management_system.csv')

print("1)Description\n2)Transpose the data\n3)Sort by axis\n4)Sort by Value")

choice = int(input("Enter your choice"))

if choice == 1:
    df.drop(df.columns[0], axis=1, inplace=True)
    print(tb(df.describe(), headers='keys', tablefmt='psql'))

elif choice == 2:
    print(tb(df.transpose(), headers='keys', tablefmt='psql'))

elif choice == 3:
    print("Enter the index to be sorted")
    axis = int(input())
    print(tb(df.sort_index(axis=axis), headers='keys', tablefmt='psql'))

elif choice == 4:
    cname = input("Enter the column name")
    print(tb(df.sort_values(by=cname), headers='keys', tablefmt='psql'))

else:
    print("Invalid choice")

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *