Day: April 6, 2021

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

Hits: 8 (Python Example for Beginners)   Write a Pandas program to count the NaN values in one or more columns in DataFrame. Sample data: Original DataFrame attempts name qualify score 0 1 Anastasia yes 12.5 1 3 Dima no 9.0 2 2 Katherine yes 16.5 3 3 James no NaN 4 2 Emily no …

Pandas Example – Write a Pandas program to convert index in a column of the given dataframe

Hits: 7 (Python Example for Beginners)   Write a Pandas program to convert index in a column of the given dataframe.   Sample Solution : Python Code : import pandas as pd import numpy as np exam_data = {‘name’: [‘Anastasia’, ‘Dima’, ‘Katherine’, ‘James’, ‘Emily’, ‘Michael’, ‘Matthew’, ‘Laura’, ‘Kevin’, ‘Jonas’], ‘score’: [12.5, 9, 16.5, np.nan, 9, 20, …

Pandas Example – Write a Pandas program to select a row of series/dataframe by given integer index

Hits: 3 (Python Example for Beginners)   Write a Pandas program to select a row of series/dataframe by given integer index. 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 Index-2: Details col1 col2 col3 2 3 6 …

Pandas Example – Write a Pandas program to widen output display to see more columns

Hits: 4 (Python Example for Beginners)   Write a Pandas program to widen output display to see more 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   Sample Solution : Python Code : import pandas as …

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

Hits: 6 (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 …

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

Hits: 2 (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 …

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

Hits: 3 (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 …

Pandas Example – Write a Pandas program to rename columns of a given DataFrame

Hits: 2 (Python Example for Beginners)   Write a Pandas program to rename columns of a given DataFrame. Sample data: Original DataFrame col1 col2 col3 0 1 4 7 1 2 5 8 2 3 6 9 New DataFrame after renaming columns: Column1 Column2 Column3 0 1 4 7 1 2 5 8 2 3 …

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

Hits: 2 (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 …

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

Hits: 2 (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, …

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

Hits: 5 (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, …

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

Hits: 3 (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, …

Pandas Example – Write a Pandas program to append a new row ‘k’ to DataFrame with given values for each column. Now delete the new row and return the original data frame

Hits: 6 (Python Example for Beginners)   Write a Pandas program to append a new row ‘k’ to DataFrame with given values for each column. Now delete the new row and return the original data frame. Sample DataFrame: exam_data = {‘name’: [‘Anastasia’, ‘Dima’, ‘Katherine’, ‘James’, ‘Emily’, ‘Michael’, ‘Matthew’, ‘Laura’, ‘Kevin’, ‘Jonas’], ‘score’: [12.5, 9, 16.5, …

Pandas Example – Write a Pandas program to calculate the mean score for each different student in data frame

Hits: 3 (Python Example for Beginners)   Write a Pandas program to calculate the mean score for each different student in data frame. 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, …

Pandas Example – Write a Pandas program to calculate the sum of the examination attempts by the students

Hits: 3 (Python Example for Beginners)   Write a Pandas program to calculate the sum of the examination attempts by the students. 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, …

Pandas Example – Write a Pandas program to select the rows where number of attempts in the examination is less than 2 and score greater than 15

Hits: 5 (Python Example for Beginners)   Write a Pandas program to select the rows where number of attempts in the examination is less than 2 and score greater than 15. 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, …