0
0
Data Analysis Pythondata~30 mins

Creating DataFrames (dict, list, CSV) in Data Analysis Python - Try It Yourself

Choose your learning style9 modes available
Creating DataFrames from Dictionary, List, and CSV
📖 Scenario: You work as a data analyst for a small bookstore. You want to organize book information using tables to analyze sales and inventory easily.
🎯 Goal: You will create tables called DataFrames from different data sources: a dictionary, a list of lists, and a CSV file. This will help you understand how to start working with data in Python.
📋 What You'll Learn
Use the pandas library to create DataFrames
Create a DataFrame from a dictionary
Create a DataFrame from a list of lists
Create a DataFrame by reading a CSV file
Print the DataFrames to see their content
💡 Why This Matters
🌍 Real World
DataFrames are the main way to organize and analyze data in many fields like sales, finance, and research.
💼 Career
Knowing how to create DataFrames from various data sources is a key skill for data analysts and data scientists.
Progress0 / 4 steps
1
Create a DataFrame from a dictionary
Import the pandas library as pd. Then create a dictionary called book_dict with these exact entries: 'Title': ['Python Basics', 'Data Science 101', 'Machine Learning'], 'Author': ['John Doe', 'Jane Smith', 'Emily Davis'], and 'Price': [29.99, 39.99, 49.99]. Finally, create a DataFrame called df_dict from book_dict using pd.DataFrame().
Data Analysis Python
Need a hint?

Use pd.DataFrame() to convert the dictionary into a DataFrame.

2
Create a DataFrame from a list of lists
Create a list of lists called book_list with these exact rows: ['Python Basics', 'John Doe', 29.99], ['Data Science 101', 'Jane Smith', 39.99], and ['Machine Learning', 'Emily Davis', 49.99]. Then create a DataFrame called df_list from book_list using pd.DataFrame() and set the column names to ['Title', 'Author', 'Price'].
Data Analysis Python
Need a hint?

Use columns=[...] to name the columns when creating the DataFrame from the list.

3
Create a DataFrame by reading a CSV file
Create a CSV file named books.csv with these exact contents including the header:
Title,Author,Price
Python Basics,John Doe,29.99
Data Science 101,Jane Smith,39.99
Machine Learning,Emily Davis,49.99
Then read this CSV file into a DataFrame called df_csv using pd.read_csv().
Data Analysis Python
Need a hint?

Use open() with mode 'w' to create the CSV file, then pd.read_csv() to read it.

4
Print all three DataFrames
Print the DataFrames df_dict, df_list, and df_csv in this exact order, each on its own line.
Data Analysis Python
Need a hint?

Use three print() statements, one for each DataFrame.