Day: April 9, 2021

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

Write a Pandas program to check whether alpha numeric values present in a given column of a DataFrame

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

Write a Pandas program to find the index of a substring of DataFrame with beginning and end position

(Python Example for Beginners)   Write a Pandas program to find the index of a substring of DataFrame with beginning and end position. Sample Solution: Python Code : import pandas as pd df = pd.DataFrame({ ‘name_code’: [‘c0001′,’1000c’,’b00c2′, ‘b2c02’, ‘c2222’], ‘date_of_birth ‘: [’12/05/2002′,’16/02/1999′,’25/09/1998′,’12/02/2022′,’15/09/1997’], ‘age’: [18.5, 21.2, 22.5, 22, 23] }) print(“Original DataFrame:”) print(df) print(“\nIndex of a …

Write a Pandas program to find the index of a given substring of a DataFrame column

(Python Example for Beginners)   Write a Pandas program to find the index of a given substring of a DataFrame column.   Sample Solution: Python Code : import pandas as pd df = pd.DataFrame({ ‘name_code’: [‘c001′,’c002′,’c022’, ‘c2002’, ‘c2222’], ‘date_of_birth ‘: [’12/05/2002′,’16/02/1999′,’25/09/1998′,’12/02/2022′,’15/09/1997’], ‘age’: [18.5, 21.2, 22.5, 22, 23] }) print(“Original DataFrame:”) print(df) print(“\nCount occurrence of 22 …

Write a Pandas program to count of occurrence of a specified substring in a DataFrame column

(Python Example for Beginners)   Write a Pandas program to count of occurrence of a specified substring in a DataFrame column.   Sample Solution: Python Code : import pandas as pd df = pd.DataFrame({ ‘name_code’: [‘c001′,’c002′,’c022’, ‘c2002’, ‘c2222’], ‘date_of_birth ‘: [’12/05/2002′,’16/02/1999′,’25/09/1998′,’12/02/2022′,’15/09/1997’], ‘age’: [18.5, 21.2, 22.5, 22, 23] }) print(“Original DataFrame:”) print(df) print(“\nCount occurrence of 2 …

Pandas Example – Write a Pandas program to capitalize all the string values of specified columns of a given DataFrame

(Python Example for Beginners)   Write a Pandas program to capitalize all the string values of specified columns of a given DataFrame.   Sample Solution: Python Code : import pandas as pd df = pd.DataFrame({ ‘name’: [‘alberto’,’gino’,’ryan’, ‘Eesha’, ‘syed’], ‘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:”) print(df) print(“nAfter capitalizing name …

Pandas Example – Write a Pandas program to convert all the string values to upper, lower cases in a given pandas series. Also find the length of the string values

(Python Example for Beginners)   Write a Pandas program to convert all the string values to upper, lower cases in a given pandas series. Also find the length of the string values.   Sample Solution: Python Code : import pandas as pd import numpy as np s = pd.Series([‘X’, ‘Y’, ‘Z’, ‘Aaba’, ‘Baca’, np.nan, ‘CABA’, …