Day: April 10, 2021

Pandas Example – Write a Pandas program to extract only phone number from the specified column of a given DataFrame.

(Python Example for Beginners)   Write a Pandas program to extract only phone number from the specified column of a given DataFrame.   Sample Solution: Python Code : import pandas as pd import re as re pd.set_option(‘display.max_columns’, 10) df = pd.DataFrame({ ‘company_code’: [‘c0001′,’c0002′,’c0003’, ‘c0003’, ‘c0004’], ‘company_phone_no’: [‘Company1-Phone no. 4695168357′,’Company2-Phone no. 8088729013′,’Company3-Phone no. 6204658086’, ‘Company4-Phone no. …

Pandas Example – Write a Pandas program to extract only number from the specified column of a given DataFrame

(Python Example for Beginners)   Write a Pandas program to extract only number from the specified column of a given DataFrame.   Sample Solution: Python Code : import pandas as pd import re as re pd.set_option(‘display.max_columns’, 10) df = pd.DataFrame({ ‘company_code’: [‘c0001′,’c0002′,’c0003’, ‘c0003’, ‘c0004’], ‘address’: [‘7277 Surrey Ave.’,’920 N. Bishop Ave.’,’9910 Golden Star St.’, ’25 …

Pandas Example – Write a Pandas program to extract word mention someone in tweets using @ from the specified column of a given DataFrame

(Python Example for Beginners)   Write a Pandas program to extract word mention someone in tweets using @ from the specified column of a given DataFrame.   Sample Solution: Python Code : import pandas as pd import re as re pd.set_option(‘display.max_columns’, 10) df = pd.DataFrame({ ‘tweets’: [‘@Obama says goodbye’,’Retweets for @cash’,’A political endorsement in @Indonesia’, …

Pandas Example – Write a Pandas program to extract hash attached word from twitter text from the specified column of a given DataFrame

(Python Example for Beginners)   Write a Pandas program to extract hash attached word from twitter text from the specified column of a given DataFrame.   Sample Solution: Python Code : import pandas as pd import re as re pd.set_option(‘display.max_columns’, 10) df = pd.DataFrame({ ‘tweets’: [‘#Obama says goodbye’,’Retweets for #cash’,’A political endorsement in #Indonesia’, ‘1 …

Pandas Example – Write a Pandas program to extract email from a specified column of string type of a given DataFrame

(Python Example for Beginners)   Write a Pandas program to extract email from a specified column of string type of a given DataFrame.   Sample Solution: Python Code : import pandas as pd import re as re pd.set_option(‘display.max_columns’, 10) df = pd.DataFrame({ ‘name_email’: [‘Alberto Franco af@gmail.com’,’Gino Mcneill gm@yahoo.com’,’Ryan Parkes rp@abc.io’, ‘Eesha Hinton’, ‘Gino Mcneill gm@github.com’] …

Pandas Example – Write a Pandas program to replace more than one value with other values in a given DataFrame

(Python Example for Beginners)   Write a Pandas program to replace more than one value with other values in a given DataFrame.   Sample Solution: Python Code : import pandas as pd df = pd.DataFrame({ ‘company_code’: [‘A’,’B’, ‘C’, ‘D’, ‘A’], ‘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(“nReplace A with …

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 …