Lesson 1 of 6
Write a Question and Create Sample Sales Data
You choose a question you can answer with sales data, define each term, and create a small CSV file with columns for date, item, quantity, and unit price.
5 minData Analysis
After this lesson, you will be able to choose a clear question about sales data, define the terms in it, and create a small CSV file with columns for date, item, quantity, and unit price.
Choose a question you can answer
A good data question is specific and can be answered with numbers. For this course, you will work with sales data. A sale is one purchase of one item by a customer. Your data will have four pieces of information for each sale: the date, the item name, the quantity sold, and the unit price.
Start with a question like this: "Which item brought in the most revenue?" Revenue is the total money from sales of an item. It is the quantity sold times the unit price, added up over all sales of that item. This question is clear because you can calculate revenue for each item and compare the numbers.
You can choose a different question if you like, but it must be answerable with the four columns: date, item, quantity, and unit price. For example, you could ask "How many units of each item were sold?" or "What was the total revenue on each date?" Keep your question simple for now. You will use it throughout the course.
Define each term in your question
Before you create data, write down what each word in your question means. This helps you avoid confusion later. For the question "Which item brought in the most revenue?", the terms are:
- Item: the name of a product sold, such as "apple" or "notebook".
- Quantity: the number of units of that item sold in one sale. It is a whole number, like 2 or 5.
- Unit price: the price of one unit of that item, in your currency, like 1.20 or 3.50.
- Revenue: the total money from sales of an item. For one sale, it is quantity times unit price. For an item overall, it is the sum of that product over all sales of that item.
Write these definitions in a plain text file called definitions.txt. This file is for you, not for the computer. It will help you remember what your data means when you come back to it later.
Create a small CSV file
CSV stands for comma-separated values. It is a plain text format for tables. Each line is a row, and commas separate the values in the row. The first line usually has the column names.
Create a file called sales.csv in your text editor. The first line must be exactly:
date,item,quantity,unit_priceThe column names are date, item, quantity, and unit_price. Use lowercase letters and an underscore between unit and price. Do not put spaces in the column names.
Now add some rows of data. Each row is one sale. Put the date in the format YYYY-MM-DD, for example 2024-01-15. The item name can be any word without a comma. The quantity is a whole number. The unit price is a number with a decimal point, like 1.20.
Here is an example with five sales:
date,item,quantity,unit_price
2024-01-15,apple,3,1.20
2024-01-15,notebook,1,3.50
2024-01-16,apple,2,1.20
2024-01-16,pen,4,0.80
2024-01-17,notebook,2,3.50You can copy this example or make your own. Use at least five rows so you have enough data to work with. Make sure each row has exactly four values, and no value contains a comma. If an item name has a comma, like "apple, red", the CSV format would need quotes around it, which we are not using here. Keep item names simple.
Save the file as sales.csv in the same folder as your definitions.txt. You will use this file in the next lesson to load the data into a database.
Check your CSV file
Open sales.csv in your text editor and look at it. Each line should have the same number of commas. The first line has three commas, separating four column names. Each data line also has three commas, separating four values.
If you see a line with more or fewer commas, fix it. A common mistake is to put a comma inside an item name or to forget a value. Your data must be consistent for the next lesson to work.
You have now completed the first step: you have a question, definitions, and a CSV file with sample sales data.
Key takeaways
- A good data question is specific and can be answered with the columns you have.
- Define each term in your question before you create data.
- A CSV file has column names in the first line and one row of data per line, with commas separating values.
- Your sales data must have columns for date, item, quantity, and unit price, with no commas inside values.
Try it
Create your own sales.csv file with at least eight rows of data. Use at least three different items. Make sure each row has a date in YYYY-MM-DD format, an item name without commas, a whole number quantity, and a unit price with a decimal point. Then write a definitions.txt file that defines the terms in your chosen question. A good result is a CSV file where every line has exactly three commas and the first line is date,item,quantity,unit_price, and a definitions file that clearly explains item, quantity, unit price, and revenue.
Official documentation
Written with AI and checked automatically. Tools change, so a command may behave differently in the version you install. Spotted a mistake? Tell us.