Day: April 8, 2021

Pandas Example – Write a Pandas program to construct a DataFrame using the MultiIndex levels as the column and index

(Python Example for Beginners)   Write a Pandas program to construct a DataFrame using the MultiIndex levels as the column and index.   Sample Solution: Python Code : import pandas as pd import numpy as np sales_arrays = [[‘sale1’, ‘sale1’, ‘sale2’, ‘sale2’, ‘sale3’, ‘sale3’, ‘sale4’, ‘sale4’], [‘city1’, ‘city2’, ‘city1’, ‘city2’, ‘city1’, ‘city2’, ‘city1’, ‘city2’]] sales_tuples …

Pandas Example – Write a Pandas program to construct a series using the MultiIndex levels as the column and index

(Python Example for Beginners)   Write a Pandas program to construct a series using the MultiIndex levels as the column and index.   Sample Solution: Python Code : import pandas as pd import numpy as np sales_arrays = [[‘sale1’, ‘sale1’, ‘sale2’, ‘sale2’, ‘sale3’, ‘sale3’, ‘sale4’, ‘sale4’], [‘city1’, ‘city2’, ‘city1’, ‘city2’, ‘city1’, ‘city2’, ‘city1’, ‘city2’]] sales_tuples …

Pandas Example – Write a Pandas program to convert 1st and 3rd levels in the index into columns from a multiple level of index frame of a given dataframe

(Python Example for Beginners)   Write a Pandas program to convert 1st and 3rd levels in the index into columns from a multiple level of index frame of a given dataframe. Test Data: 0 s001 V Alberto Franco 15/05/2002 35 street1 t1 1 s002 V Gino Mcneill 17/05/2002 32 street2 t2 2 s003 VI Ryan Parkes 16/02/1999 …

Pandas Example – Write a Pandas program to convert index of a given dataframe into a column

(Python Example for Beginners)   Write a Pandas program to convert index of a given dataframe into a column. Test Data: 0 s001 V Alberto Franco 15/05/2002 35 street1 t1 1 s002 V Gino Mcneill 17/05/2002 32 street2 t2 2 s003 VI Ryan Parkes 16/02/1999 33 street3 t3 3 s001 VI Eesha Hinton 25/09/1998 30 …

Pandas Example – Write a Pandas program to create a dataframe indexing by date and time

(Python Example for Beginners)   Write a Pandas program to create a dataframe indexing by date and time. Test Data: 0 s001 V Alberto Franco 15/05/2002 35 street1 t1 1 s002 V Gino Mcneill 17/05/2002 32 street2 t2 2 s003 VI Ryan Parkes 16/02/1999 33 street3 t3 3 s001 VI Eesha Hinton 25/09/1998 30 street1 …

Pandas Example – Write a Pandas program to display the default index and set a column as an Index in a given dataframe and then reset the index

(Python Example for Beginners)   Write a Pandas program to display the default index and set a column as an Index in a given dataframe and then reset the index. Test Data: 0 s001 V Alberto Franco 15/05/2002 35 street1 t1 1 s002 V Gino Mcneill 17/05/2002 32 street2 t2 2 s003 VI Ryan Parkes …

Pandas Example – Write a Pandas program to create a multi Index frame using two columns and using an Index and a column

(Python Example for Beginners)   Write a Pandas program to create a multi Index frame using two columns and using an Index and a column. Test Data: 0 s001 V Alberto Franco 15/05/2002 35 street1 t1 1 s002 V Gino Mcneill 17/05/2002 32 street2 t2 2 s003 VI Ryan Parkes 16/02/1999 33 street3 t3 3 …

Pandas Example – Write a Pandas program to display the default index and set a column as an Index in a given dataframe

(Python Example for Beginners)   Write a Pandas program to display the default index and set a column as an Index in a given dataframe. Test Data: 0 s001 V Alberto Franco 15/05/2002 35 street1 t1 1 s002 V Gino Mcneill 17/05/2002 32 street2 t2 2 s003 VI Ryan Parkes 16/02/1999 33 street3 t3 3 …

Pandas Example – Write a Pandas program to get the numeric representation of an array by identifying distinct values of a given column of a DataFrame

(Python Example for Beginners)   Write a Pandas program to get the numeric representation of an array by identifying distinct values of a given column of a DataFrame.   Sample Solution : Python Code : import pandas as pd df = pd.DataFrame({ ‘Name’: [‘Alberto Franco’,’Gino Mcneill’,’Ryan Parkes’, ‘Eesha Hinton’, ‘Gino Mcneill’], ‘Date_Of_Birth ‘: [’17/05/2002′,’16/02/1999′,’25/09/1998′,’11/05/2002′,’15/09/1997’], ‘Age’: [18.5, …