Tag Archives: python for data analyst

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 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, …

Pandas Example – Write a Pandas program to fill missing values in time series data

(Python Example for Beginners)   Write a Pandas program to fill missing values in time series data. From Wikipedia , in the mathematical field of numerical analysis, interpolation is a type of estimation, a method of constructing new data points within the range of a discrete set of known data points.   Sample Solution : Python …

Pandas Example – Write a Pandas program to combine many given series to create a DataFrame

(Python Example for Beginners)   Write a Pandas program to combine many given series to create a DataFrame.   Sample Solution : Python Code : import pandas as pd sr1 = pd.Series([‘php’, ‘python’, ‘java’, ‘c#’, ‘c++’]) sr2 = pd.Series([1, 2, 3, 4, 5]) print(“Original Series:”) print(sr1) print(sr2) print(“Combine above series to a dataframe:”) ser_df = pd.DataFrame(sr1, …

Pandas Example – Write a Pandas program to convert continuous values of a column in a given DataFrame to categorical

(Python Example for Beginners)   Write a Pandas program to convert continuous values of a column in a given DataFrame to categorical. Input: { ‘Name’: [‘Alberto Franco’,’Gino Mcneill’,’Ryan Parkes’, ‘Eesha Hinton’, ‘Syed Wharton’], ‘Age’: [18, 22, 40, 50, 80, 5] } Output: Age group: 0 kids 1 adult 2 elderly 3 adult 4 elderly 5 …

Pandas Example – Write a Pandas program to rename all columns with the same pattern of a given DataFrame

(Python Example for Beginners)   Write a Pandas program to rename all columns with the same pattern of a given DataFrame.   Sample Solution : Python Code : import pandas as pd df = pd.DataFrame({ ‘Name’: [‘Alberto Franco’,’Gino Mcneill’,’Ryan Parkes’, ‘Eesha Hinton’, ‘Syed Wharton’], ‘Date_Of_Birth ‘: [’17/05/2002′,’16/02/1999′,’25/09/1998′,’11/05/2002′,’15/09/1997’], ‘Age’: [18.5, 21.2, 22.5, 22, 23] }) print(“Original DataFrame”) …