Python for Business Analyst

Pandas Example – Write a Pandas program to convert a specified character column in title case in a given DataFrame

(Python Example for Beginners)   Write a Pandas program to convert a specified character column in title case in a given DataFrame.   Sample Solution: Python Code : import pandas as pd df = pd.DataFrame({ ‘company_code’: [‘Abcd’,’EFGF’, ‘zefsalf’, ‘sdfslew’, ‘zekfsdf’], ‘date_of_sale’: [’12/05/2002′,’16/02/1999′,’25/09/1998′,’12/02/2022′,’15/09/1997′], ‘sale_amount’: [12348.5, 233331.2, 22.5, 2566552.0, 23.0] }) print(“Original DataFrame:”) print(df) print(“nTitle cases:”) df[‘company_code_title_cases’] …

Pandas Example – Write a Pandas program to filter words from a given series that contain atleast two vowels

(Python Example for Beginners)   Write a Pandas program to swap the cases of a specified character column in a given DataFrame.   Sample Solution: Python Code : import pandas as pd df = pd.DataFrame({ ‘company_code’: [‘Abcd’,’EFGF’, ‘zefsalf’, ‘sdfslew’, ‘zekfsdf’], ‘date_of_sale’: [’12/05/2002′,’16/02/1999′,’25/09/1998′,’12/02/2022′,’15/09/1997′], ‘sale_amount’: [12348.5, 233331.2, 22.5, 2566552.0, 23.0] }) print(“Original DataFrame:”) print(df) print(“nSwapp cases in …

Pandas Example – Write a Pandas program to filter words from a given series that contain atleast two vowels

(Python Example for Beginners)   Write a Pandas program to check if a specified column starts with a specified string in a DataFrame.   Sample Solution: Python Code : import pandas as pd df = pd.DataFrame({ ‘company_code’: [‘Abcd’,’EFGF’, ‘zefsalf’, ‘sdfslew’, ‘zekfsdf’], ‘date_of_sale’: [’12/05/2002′,’16/02/1999′,’25/09/1998′,’12/02/2022′,’15/09/1997′], ‘sale_amount’: [12348.5, 233331.2, 22.5, 2566552.0, 23.0] }) print(“Original DataFrame:”) print(df) print(“nIf a …

Pandas Example – Write a Pandas program to get the length of the string present of a given column in a DataFrame

(Python Example for Beginners)   Write a Pandas program to get the length of the string present of a given column in a DataFrame.   Sample Solution: Python Code : import pandas as pd df = pd.DataFrame({ ‘company_code’: [‘Abcd’,’EFGF’, ‘skfsalf’, ‘sdfslew’, ‘safsdf’], ‘date_of_sale ‘: [’12/05/2002′,’16/02/1999′,’25/09/1998′,’12/02/2022′,’15/09/1997’], ‘sale_amount’: [12348.5, 233331.2, 22.5, 2566552.0, 23.0]}) print(“Original DataFrame:”) print(df) print(“nLength …

Pandas Example – Write a Pandas program to check whether only space is present in a given column of a DataFrame

(Python Example for Beginners)   Write a Pandas program to check whether only space is present in a given column of a DataFrame.   Sample Solution: Python Code : import pandas as pd df = pd.DataFrame({ ‘company_code’: [‘Abcd’,’EFGF ‘, ‘ ‘, ‘abcd’, ‘ ‘], ‘date_of_sale ‘: [’12/05/2002′,’16/02/1999′,’25/09/1998′,’12/02/2022′,’15/09/1997’], ‘sale_amount’: [12348.5, 233331.2, 22.5, 2566552.0, 23.0]}) print(“Original DataFrame:”) …

Pandas Example – Write a Pandas program to check whether only proper case or title case is present in a given column of a DataFrame

(Python Example for Beginners)   Write a Pandas program to check whether only proper case or title case is present in a given column of a DataFrame.   Sample Solution: Python Code : import pandas as pd df = pd.DataFrame({ ‘company_code’: [‘Abcd’,’EFGF’, ‘Hhhh’, ‘abcd’, ‘EAWQaaa’], ‘date_of_sale ‘: [’12/05/2002′,’16/02/1999′,’25/09/1998′,’12/02/2022′,’15/09/1997’], ‘sale_amount’: [12348.5, 233331.2, 22.5, 2566552.0, 23.0]}) print(“Original …

Pandas Example – Write a Pandas program to check whether only lower case or upper case is present in a given column of a DataFrame

(Python Example for Beginners)   Write a Pandas program to check whether only lower case or upper case is present in a given column of a DataFrame.   Sample Solution: Python Code : import pandas as pd df = pd.DataFrame({ ‘company_code’: [‘ABCD’,’EFGF’, ‘hhhh’, ‘abcd’, ‘EAWQaaa’], ‘date_of_sale ‘: [’12/05/2002′,’16/02/1999′,’25/09/1998′,’12/02/2022′,’15/09/1997’], ‘sale_amount’: [12348.5, 233331.2, 22.5, 2566552.0, 23.0]}) print(“Original …

Pandas Example – Write a Pandas program to check whether only lower case or upper case is present in a given column of a DataFrame

(Python Example for Beginners)   Write a Pandas program to check whether only lower case or upper case is present in a given column of a DataFrame.   Sample Solution: Python Code : import pandas as pd df = pd.DataFrame({ ‘company_code’: [‘ABCD’,’EFGF’, ‘hhhh’, ‘abcd’, ‘EAWQaaa’], ‘date_of_sale ‘: [’12/05/2002′,’16/02/1999′,’25/09/1998′,’12/02/2022′,’15/09/1997’], ‘sale_amount’: [12348.5, 233331.2, 22.5, 2566552.0, 23.0]}) print(“Original …

Pandas Example – Write a Pandas program to check whether only numeric values present in a given column of a DataFrame

(Python Example for Beginners)   Write a Pandas program to check whether only numeric values present in a given column of a DataFrame.   Sample Solution: Python Code : import pandas as pd df = pd.DataFrame({ ‘company_code’: [‘Company’,’Company a001′, ‘2055’, ‘abcd’, ‘123345’], ‘date_of_sale ‘: [’12/05/2002′,’16/02/1999′,’25/09/1998′,’12/02/2022′,’15/09/1997’], ‘sale_amount’: [12348.5, 233331.2, 22.5, 2566552.0, 23.0]}) print(“Original DataFrame:”) print(df) print(“nNumeric …

Pandas Example – Write a Pandas program to check whether alphabetic values present in a given column of a DataFrame

(Python Example for Beginners)   Write a Pandas program to check whether alphabetic values present in a given column of a DataFrame. Note: isalpha() returns True if all characters in the string are alphabetic and there is at least one character, False otherwise.   Sample Solution: Python Code : import pandas as pd df = …