(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 9 …
Month: April 2021
(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 pd import …
(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 = …
(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 …
(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 …
(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 6 9 …
(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 …
(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, …
(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’: …
(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, …