Tag Archives: python for beginners

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

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

(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, np.nan, 9, …

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

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

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

(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, 1, 1, …