Day: April 11, 2021

Pandas Example – Write a Pandas program to append rows to an existing DataFrame and display the combined data

(Python Example for Beginners)   Write a Pandas program to append rows to an existing DataFrame and display the combined data.   Test Data: student_data1 student_id name marks 0 S1 Danniella Fenton 200 1 S2 Ryder Storey 210 2 S3 Bryce Jensen 190 3 S4 Ed Bernal 222 4 S5 Kwame Morin 199 New Row(s) …

Pandas Example – Write a Pandas program to join the two given dataframes along rows and assign all data

(Python Example for Beginners)   Write a Pandas program to join the two given dataframes along rows and assign all data.   Test Data: student_data1: student_id name marks 0 S1 Danniella Fenton 200 1 S2 Ryder Storey 210 2 S3 Bryce Jensen 190 3 S4 Ed Bernal 222 4 S5 Kwame Morin 199 student_data2: student_id …

Pandas Example – Write a Pandas program to remove the html tags within the specified column of a given DataFrame

(Python Example for Beginners)   Write a Pandas program to remove the html tags within the specified column of a given DataFrame.   Sample Solution: Python Code : import pandas as pd import re as re df = pd.DataFrame({ ‘company_code’: [‘Abcd’,’EFGF’, ‘zefsalf’, ‘sdfslew’, ‘zekfsdf’], ‘date_of_sale’: [’12/05/2002′,’16/02/1999′,’05/09/1998′,’12/02/2022′,’15/09/1997′], ‘address’: [‘9910 Surrey <b>Avenue</b>’,’92 N. Bishop Avenue’,’9910 <br>Golden Star …

Pandas Example – Write a Pandas program to extract words starting with capital words from a given column of a given DataFrame

(Python Example for Beginners)   Write a Pandas program to extract words starting with capital words from a given column of a given DataFrame.   Sample Solution: Python Code : import pandas as pd import re as re df = pd.DataFrame({ ‘company_code’: [‘Abcd’,’EFGF’, ‘zefsalf’, ‘sdfslew’, ‘zekfsdf’], ‘date_of_sale’: [’12/05/2002′,’16/02/1999′,’05/09/1998′,’12/02/2022′,’15/09/1997′], ‘address’: [‘9910 Surrey Avenue’,’92 N. Bishop Avenue’,’9910 …

Pandas Example – Write a Pandas program to extract the unique sentences from a given column of a given DataFrame

(Python Example for Beginners)   Write a Pandas program to extract the unique sentences from a given column of a given DataFrame.   Sample Solution: Python Code : import pandas as pd import re as re df = pd.DataFrame({ ‘company_code’: [‘Abcd’,’EFGF’, ‘zefsalf’, ‘sdfslew’, ‘zekfsdf’], ‘date_of_sale’: [’12/05/2002′,’16/02/1999′,’05/09/1998′,’12/02/2022′,’15/09/1997′], ‘address’: [‘9910 Surrey Avenuen9910 Surrey Avenue’,’92 N. Bishop Avenue’,’9910 …

Pandas Example – Write a Pandas program to remove repetitive characters from the specified column of a given DataFrame

(Python Example for Beginners)   Write a Pandas program to remove repetitive characters 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({ ‘text_code’: [‘t0001.’,’t0002′,’t0003′, ‘t0004’], ‘text_lang’: [‘She livedd a long life.’, ‘How oold is your father?’, ‘What …

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

(Python Example for Beginners)   Write a Pandas program to extract only non alphanumeric characters 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#’,’c00@0^2′,’$c0003′, ‘c0003’, ‘&c0004’], ‘year’: [‘year 1800′,’year 1700′,’year 2300’, ‘year 1900’, ‘year 2200’] …