Python Practice › Pandas Programs
Python Pandas Programs with Solutions
95 pandas programs: Series arithmetic and statistics, building and filtering DataFrames, sorting, adding and renaming columns, string methods, joining tables and handling missing values. Outputs come from pandas 3; the in-browser Try it uses an older pandas, so some printouts (such as column types) may differ slightly.
Before you start
Read the Pandas lesson first if the topic is new to you.
All programs
- #1Create a Series
Write a pandas program to create and display a one-dimensional Series.Easy - #2Series to list
Write a pandas program to convert a Series to a list and print its type.Easy - #3Add two Series
Write a pandas program to add two Series.Easy - #4Subtract two Series
Write a pandas program to subtract two Series.Easy - #5Multiply two Series
Write a pandas program to multiply two Series.Easy - #6Divide two Series
Write a pandas program to divide two Series.Easy - #7Are Series elements equal?
Write a pandas program to compare two Series element by element.Easy - #8Is one Series greater?
Write a pandas program to check element-wise whether one Series is greater than another.Easy - #9Dictionary to Series
Write a pandas program to convert a dictionary to a Series.Easy - #10NumPy array to Series
Write a pandas program to convert a NumPy array to a Series.Easy - #11Convert a Series to numbers
Write a pandas program to convert a mixed Series to numbers, turning text into NaN.Easy - #12Series to array
Write a pandas program to convert a Series to a NumPy array.Easy - #13Series of lists to one Series
Write a pandas program to turn a Series of lists into one flat Series.Easy - #14Sort a Series
Write a pandas program to sort a Series.Easy - #15Add data to a Series
Write a pandas program to add new values to an existing Series.Easy - #16Subset by condition
Write a pandas program to select the values below 40.Easy - #17Reorder the index
Write a pandas program to change the order of a Series’ index.Easy - #18Mean of a Series
Write a pandas program to find the mean of a Series.Easy - #19Standard deviation of a Series
Write a pandas program to find the standard deviation of a Series.Easy - #20Items not in another Series
Write a pandas program to get the items of one Series not present in another.Easy - #21Maximum of a Series
Write a pandas program to find the maximum value.Easy - #22Minimum of a Series
Write a pandas program to find the minimum value.Easy - #23Frequency of each value
Write a pandas program to count each value.Easy - #24Items at positions
Write a pandas program to extract items at positions 1, 4 and 7.Easy - #25Capitalise first and last letters
Write a pandas program to make the first and last letter of each word uppercase.Easy - #26Length of each word
Write a pandas program to count the characters of each word.Easy - #27Date strings to datetimes
Write a pandas program to convert date strings in different formats into datetimes.Easy - #28Index of smallest and largest
Write a pandas program to find the index of the smallest and largest values.Easy - #29Dictionary to DataFrame
Write a pandas program to convert a dictionary into a DataFrame.Easy - #30First n rows
Write a pandas program to print the first n rows.Easy - #31Last n rows
Write a pandas program to print the last n rows.Easy - #32Select columns
Write a pandas program to print selected columns.Easy - #33Select a row
Write a pandas program to print a selected row.Easy - #34Rows where age > 29
Write a pandas program to select the rows where age is greater than 29.Easy - #35Count rows and columns
Write a pandas program to count the rows and columns.Easy - #36Rows with missing age
Write a pandas program to select rows where age is missing.Easy - #37Ages between 25 and 30
Write a pandas program to print rows where age is between 25 and 30.Easy - #38Change one value
Write a pandas program to change John’s age to 24.Easy - #39Sum of a column
Write a pandas program to sum the age column.Easy - #40Add a row
Write a pandas program to add a new row.Easy - #41Sort by name
Write a pandas program to sort by name in ascending order.Easy - #42Mean of a column
Write a pandas program to find the mean age.Easy - #43Sort by age
Write a pandas program to sort by age in ascending order.Easy - #44Replace a value
Write a pandas program to replace John with Jim.Easy - #45Delete rows
Write a pandas program to delete John’s record.Easy - #46Add a column
Write a pandas program to add a salary column.Easy - #47Iterate over rows
Write a pandas program to iterate over the rows.Easy - #48Column headers
Write a pandas program to get a list of column headers.Easy - #49Rename all columns
Write a pandas program to rename columns C1, C2, C3 to A, B, C.Easy - #50Reorder columns
Write a pandas program to change the order of columns.Easy - #51Write a tab-separated file
Write a pandas program to write a DataFrame to a CSV file with a tab separator.Easy - #52Population per country
Write a pandas program to total the population per country from a data set.Easy - #53Replace NaN with a value
Write a pandas program to replace NaN in a column with a fixed value.Easy - #54Count NaN values
Write a pandas program to count NaN values.Easy - #55Shuffle rows
Write a pandas program to shuffle rows.Easy - #56Rename one column
Write a pandas program to rename one column.Easy - #57Column values as a list
Write a pandas program to get the values of a column as a list.Easy - #58Row with the maximum value
Write a pandas program to find the row where a column is largest.Easy - #59Row with the minimum value
Write a pandas program to find the row where a column is smallest.Easy - #60Is a column present?
Write a pandas program to check whether a column exists.Easy - #61Column data types
Write a pandas program to get the data type of each column.Easy - #62List of lists to DataFrame
Write a pandas program to convert a list of lists into a DataFrame.Easy - #63Index of a column
Write a pandas program to find the position of a column.Easy - #64All columns except one
Write a pandas program to select all columns except one.Easy - #65Remove the first n rows
Write a pandas program to remove the first n rows.Easy - #66Remove the last n rows
Write a pandas program to remove the last n rows.Easy - #67Reverse row order
Write a pandas program to reverse the order of rows.Easy - #68Reverse column order
Write a pandas program to reverse the order of columns.Easy - #69Select text columns
Write a pandas program to select the text columns.Easy - #70Capitalise text values
Write a pandas program to capitalise the text values of a column.Easy - #71Uppercase-only check
Write a pandas program to check which values are fully uppercase.Easy - #72Lowercase-only check
Write a pandas program to check which values are fully lowercase.Easy - #73Numeric-only check
Write a pandas program to check which values contain only digits.Easy - #74Alphabetic-only check
Write a pandas program to check which values contain only letters.Easy - #75Number of digits
Write a pandas program to count the digits of each integer in a column.Easy - #76Extract emails
Write a pandas program to extract email addresses from a column.Easy - #77Extract hashtags
Write a pandas program to extract hashtag words from tweets.Easy - #78Keep only words
Write a pandas program to remove the numbers from an address column and keep the words.Easy - #79Join along rows
Write a pandas program to join two DataFrames along rows.Easy - #80Join along columns
Write a pandas program to join two DataFrames side by side.Easy - #81Merge on a common column
Write a pandas program to join two DataFrames on their common column.Easy - #82Merge with different columns
Write a pandas program to merge two DataFrames with different columns, keeping all rows.Easy - #83Detect missing values
Write a pandas program to show where values are missing.Easy - #84Columns with missing values
Write a pandas program to find the columns with at least one missing value.Easy - #85Missing values per column
Write a pandas program to count the missing values in each column.Easy - #86Drop rows with any missing value
Write a pandas program to drop rows where at least one value is missing.Easy - #87Drop columns with missing values
Write a pandas program to drop columns where at least one value is missing.Easy - #88Drop rows that are entirely missing
Write a pandas program to drop rows where all values are missing.Easy - #89Fill from the previous row
Write a pandas program to replace NaN with the value from the previous row.Easy - #90Fill from the next row
Write a pandas program to replace NaN with the value from the next row.Easy - #91Fill with the mean
Write a pandas program to replace NaN with the column mean.Easy - #92Fill with the most frequent value
Write a pandas program to replace NaN with each column’s most frequent value.Easy - #93Fill with the median
Write a pandas program to replace NaN with the median.Easy - #94Import a CSV file
Write a pandas program to import a CSV file.Easy - #95Import an Excel file
Write a pandas program to import an .xlsx file.Easy