Introduction to Pandas
Use Pandas to create and manipulate tables so that you can process your data faster and get your insights sooner.
StartKey Concepts
Review core concepts you need to learn to master this subject
Pandas DataFrame creation
Pandas
Selecting Pandas DataFrame rows using logical operators
Pandas apply() function
Pandas DataFrames adding columns
Pandas DataFrame creation
Pandas DataFrame creation
# Ways of creating a Pandas DataFrame
# Passing in a dictionary:
data = {'name':['Anthony', 'Maria'], 'age':[30, 28]}
df = pd.DataFrame(data)
# Passing in a list of lists:
data = [['Tom', 20], ['Jack', 30], ['Meera', 25]]
df = pd.DataFrame(data, columns = ['Name', 'Age'])
# Reading data from a csv file:
df = pd.read_csv('students.csv')
The fundamental Pandas object is called a DataFrame. It is a 2-dimensional size-mutable, potentially heterogeneous, tabular data structure.
A DataFrame can be created multiple ways. It can be created by passing in a dictionary or a list of lists to the pd.DataFrame()
method, or by reading data from a CSV file.
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory
Creating, Loading, and Selecting Data with Pandas
Consider the following code that is intended to create a new DataFrame showing the grades of students in a class. Will this code create a valid DataFrame? If not, why?
Modifying DataFrames
Consider the following DataFrame showing the daily inventory and amount of products sold of a local office supply store. You want to add a column to this DataFrame to determine how many of each item is remaining at the end of the day. Which of the following lines of code would accomplish this? | |product|price|initial_inventory|number_sold| |-|-|-|-|-| |0|pencil-pack|0.05|35|12| |1|pens-pack|3.10|15|14| |2|notebook|5.00|10|3| |3|tape-dispenser|4.25|20|18| |4|stapler|3.50|8|3|