Month: April 2021

Pandas Example – Write a Pandas program to count city wise number of people from a given of data set (city, name of the person)

(Python Example for Beginners)   Write a Pandas program to count city wise number of people from a given of data set (city, name of the person). Sample data: city Number of people 0 California 4 1 Georgia 2 2 Los Angeles 4   Sample Solution : Python Code : import pandas as pd df1 = …

Pandas Example – Write a Pandas program to write a DataFrame to CSV file using tab separator

(Python Example for Beginners)   Write a Pandas program to write a DataFrame to CSV file using tab separator. Sample data: Original DataFrame col1 col2 col3 0 1 4 7 1 4 5 8 2 3 6 9 3 4 7 0 4 5 8 1 Data from new_file.csv file: col1tcol2tcol3 0 1t4t7 1 4t5t8 …

Pandas Example – Write a Pandas program to change the order of a DataFrame columns

(Python Example for Beginners)   Write a Pandas program to change the order of a DataFrame columns. Sample data: Original DataFrame col1 col2 col3 0 1 4 7 1 4 5 8 2 3 6 9 3 4 7 0 4 5 8 1 After altering col1 and col3 col3 col2 col1 0 7 4 …

Pandas Example – Write a Pandas program to iterate over rows in a DataFrame

(Python Example for Beginners)   Write a Pandas program to iterate over rows in a DataFrame. Sample Python dictionary data and list labels: exam_data = [{‘name’:’Anastasia’, ‘score’:12.5}, {‘name’:’Dima’,’score’:9}, {‘name’:’Katherine’,’score’:16.5}]   Sample Solution : Python Code : import pandas as pd import numpy as np exam_data = [{‘name’:’Anastasia’, ‘score’:12.5}, {‘name’:’Dima’,’score’:9}, {‘name’:’Katherine’,’score’:16.5}] df = pd.DataFrame(exam_data) for index, row …

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 insert a new column in existing DataFrame. Sample DataFrame: Sample Python dictionary data and list labels: exam_data = {‘name’: [‘Anastasia’, ‘Dima’, ‘Katherine’, ‘James’, ‘Emily’, ‘Michael’, ‘Matthew’, ‘Laura’, ‘Kevin’, ‘Jonas’], ‘score’: [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19], ‘attempts’: [1, 3, 2, 3, …

Pandas Example – Write a Pandas program to delete the ‘attempts’ column from the DataFrame

(Python Example for Beginners)   Write a Pandas program to delete the ‘attempts’ column from the DataFrame. Sample DataFrame: exam_data = {‘name’: [‘Anastasia’, ‘Dima’, ‘Katherine’, ‘James’, ‘Emily’, ‘Michael’, ‘Matthew’, ‘Laura’, ‘Kevin’, ‘Jonas’], ‘score’: [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19], ‘attempts’: [1, 3, 2, 3, 2, 3, 1, 1, 2, 1], ‘qualify’: …

Pandas Example – Write a Pandas program to replace the ‘qualify’ column contains the values ‘yes’ and ‘no’ with True and False

(Python Example for Beginners)   Write a Pandas program to replace the ‘qualify’ column contains the values ‘yes’ and ‘no’ with True and False. Sample DataFrame: exam_data = {‘name’: [‘Anastasia’, ‘Dima’, ‘Katherine’, ‘James’, ‘Emily’, ‘Michael’, ‘Matthew’, ‘Laura’, ‘Kevin’, ‘Jonas’], ‘score’: [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19], ‘attempts’: [1, 3, 2, 3, …