Dropping Columns and Changing the index of a dataframe - Python
Event Management System II- Eliminate Column
Sunil, an event manager found his data set was cleaned by the development team and was as required. He also found that his data set was cleaned based on the missing values in rows. He thought it would be helpful if the data set was cleaned based on columns.
So, he requests the development team to do the needful. Assume that you are currently working under development team. Frame a dataset (having 10 rows and 10columns of data) for Event Management System. Consider the threshold as all values should be available, (ie. all the values should be available in a column.) If any value is missing, then drop the particular column.
Input Format:
Create a CSV file containing the data set of 10 rows and 10 columns.
NOTE:
CSV File contains the comma seperated values as shown below.
[SlNo,EventName,EventManager,NoOfDates,StartDate,EndDate,HallName,HallAddress,HallPricePerDay,TotalCost]
Output Format:
The output should display the data after dropping the rows with missing values from the data set.
[Refer Sample Input and Output format for format specifications. All text in bold correspond to Input and rest correspond to output.]
Sample Input:
EventManagementSystem.csv
HINT: The EventManagementSystem.csv file can contain the data in the following format.
Sample Output:
So, he requests the development team to do the needful. Assume that you are currently working under development team. Frame a dataset (having 10 rows and 10columns of data) for Event Management System. Consider the threshold as all values should be available, (ie. all the values should be available in a column.) If any value is missing, then drop the particular column.
Input Format:
Create a CSV file containing the data set of 10 rows and 10 columns.
NOTE:
CSV File contains the comma seperated values as shown below.
[SlNo,EventName,EventManager,NoOfDates,StartDate,EndDate,HallName,HallAddress,HallPricePerDay,TotalCost]
Output Format:
The output should display the data after dropping the rows with missing values from the data set.
[Refer Sample Input and Output format for format specifications. All text in bold correspond to Input and rest correspond to output.]
Sample Input:
EventManagementSystem.csv
HINT: The EventManagementSystem.csv file can contain the data in the following format.
EventName EventManager NoOfDays StartDate EndDate HallName HallAddress HallPricePerDay TotalCost
krishnanand 2 12-08-2005 13-08-2005 Krishna mansion Krishna Mansion, Krishnalaya, Shringeri 60000 120000
Birthday Celebration Akshay 1 14-08-2005 14-08-2005 Akshayalaya Akshayalaya, Akshaya Dama, Shimoga 35000 35000
House Warming Sunil 1 21-10-2005 21-10-2005 Sugamya Corner Sugamya corner, Vijaya Nagar, Mysore 50000 50000
Naming Ceremony Surya 1 10-11-2005 10-11-2005 Suryodaya comforts Suryodaya comforts, Srirampura 20000 20000
Promotion Celebration Aliya 1 15-11-2005 15-11-2005 Kabule convention hall 20000 20000
New Year Celebration Chandan 2 31-12-2005 01-12-2005 Chinnaswamy stadium Bangalore 12000 24000
Chrismas Celebration Collin 2 24-12-2005 25-12-2005 Saint Philominas church Mysore 25000 50000
Project outing Yaradru 2 29-11-2005 30-11-2005 Mysore Palace Mysore 15000
Sample Output:
+----+-------+----------------------+------------+-------------------------+--------------------------------------------------+-----------------+-----------+
| | Sl_No | EventManager | EndDate | HallName | HallAddress | HallPricePerDay | TotalCost |
+----+-------+----------------------+------------+-------------------------+--------------------------------------------------+-----------------+-----------+
| 0 | 1 | krishnanand | 13-08-2005 | krishna mansion | Krishna Mansion ,Krishnalaya,Shringeri | 60000 | 120000 |
| 1 | 2 | Akshay | 14-08-2005 | Akshayalaya | Akshayalaya, Akshaya Dama,Yogendra Nagar,Shimoga | 35000 | 35000 |
| 2 | 3 | sunil | 21-10-2005 | Sugamya Corner | sugamya corner ,Vijaya nagar,Mysore | 50000 | 50000 |
| 3 | 4 | Surya | 10-11-2005 | Suryodaya comforts | Suryodaya comforts,Srirampura | 20000 | 20000 |
| 4 | 5 | Aliya | 15-11-2005 | Kabule convention hall | Nr Mohalla,Mysore | 20000 | 20000 |
| 5 | 6 | Chandan v | 01-12-2005 | Chinnaswammy stadium | Bangalore | 12000 | 24000 |
| 6 | 7 | Collin | 25-12-2005 | Saint Philominas chruch | Mysore | 25000 | 50000 |
| 7 | 8 | Yaradru | 30-11-2005 | Lalth Mahal Palace | Mysore | 15000 | 30000 |
| 8 | 9 | Akshay | 14-08-2005 | Akshayalaya | Akshayalaya, Akshaya Dama,Yogendra Nagar,Shimoga | 35000 | 35000 |
| 9 | 10 | krishnanand | 13-08-2005 | krishna mansion | Krishna Mansion ,Krishnalaya,Shringeri | 60000 | 120000 |
| 10 | 11 | krishnanand | 16-08-2005 | krishna mansion | Krishna Mansion ,Krishnalaya,Shringeri | 60000 | 60000 |
+----+-------+----------------------+------------+-------------------------+--------------------------------------------------+-----------------+-----------+
Solution:
import pandas as pd
import numpy as np
from tabulate import tabulate
df = pd.read_csv('Event_Management_system.csv')
df = df.replace('', np.nan, regex=True)
df = df.dropna(axis = 1)
print(tabulate(df, headers ='keys', tablefmt = 'psql'))
Comments
Post a Comment