Descriptive Statistics and EDA


Descriptive Statistics and EDA

Corey
Descriptive statistics and exploratory data analysis may sound like a mouthful, but the basic goal is practical: understand what is in a dataset before trying to draw deeper conclusions. In this tutorial, we're working with a New York taxi dataset that has already been cleaned by removing duplicates and missing values.

Anna
And cleaning is only the beginning. Descriptive analysis gives us the first insights into how the data looks, whether it contains unusual values, and which patterns might be worth exploring further.

Corey
Exactly. The first tools are simple mathematical summaries: the mean or average, the median, the minimum, and the maximum. These numbers help us get a feel for the data and can reveal problems that were not obvious during the initial cleanup.

Anna
So descriptive statistics are not just about producing numbers. They can also help identify outliers, right?

Corey
Right. An outlier is a data point that falls outside the normal range of the rest of the data. Imagine measuring people's heights and finding that most values are between six and seven feet, but one value says ten feet. That value does not fit the normal range and may indicate an error or other anomalous behavior.

Anna
That makes an outlier sound like a warning sign rather than something we automatically delete.

Corey
That's a useful way to think about it. The analysis alerts us that something needs attention. A simple example of why this matters is a company trying to find its most frequently asked questions so it can decide which ones to keep in a new data center. Looking at the data's patterns and frequencies helps answer that kind of question.

Anna
Let's apply that to the taxi data. What is the first step in the spreadsheet?

Corey
First, create a separate sheet for the summaries so the descriptive statistics do not get mixed into the raw data. In Google Sheets, click the plus button at the bottom left, then rename the new sheet descriptive statistics.

Anna
And the example focuses on the fare amount column?

Corey
Yes. Set up headings for the statistic and the parameter being analyzed, such as fare amount. Then calculate the mean, median, minimum, and maximum fare. These summaries provide different views of the same column.

Anna
Let's clarify the mean and median, because they are often confused.

Corey
The mean is calculated by adding all the values and dividing by the number of values. Because it uses every value, it is sensitive to extreme values. The median is found by arranging the values in order and selecting the central value, so it can give a more representative picture when unusually high or low values affect the mean.

Anna
How would we calculate those in the sheet?

Corey
Start a formula with an equals sign. For the average, type the average function, select the original data sheet, choose the fare amount column, close the bracket, and press Enter. You can use the same approach with the median, minimum, and maximum functions, selecting the same column each time.

Anna
The median in the example was 9.5, which suggests that the typical fare was around that amount, even though some fares could be much lower or higher.

Corey
Correct. But the minimum revealed something more serious: a fare amount of negative 243. That clearly does not look like a valid fare, and it shows how a basic summary can uncover a data-quality problem.

Anna
Would it be enough to delete that one value?

Corey
Not necessarily. There may be other negative fares, so the better approach is to identify all of them. Sort the original sheet by fare amount in ascending order, meaning the lowest values appear first. In the sorting options, indicate that the sheet has a header row and sort by the fare column from lowest to highest.

Anna
Then all the negative values should appear together at the top.

Corey
Exactly. Select the rows from the first negative value through the last negative value, using Shift to select the range, then right-click and delete the selected rows. The example contained almost 400 such data points. The data also showed many zero fares, but those were kept at that stage because the analyst chose not to delete them.

Anna
After removing the negative values, the descriptive statistics can be checked again to confirm that the minimum now makes sense.

Corey
Yes. This illustrates an important workflow: summarize the data, notice an abnormal result, investigate the underlying records, fix the issue, and then continue the analysis.

Anna
Once the data quality check is done, exploratory analysis begins with a question: what are we actually trying to find out?

Corey
That question is central to a data analyst's work. Before analyzing, define questions that matter to the business or the situation. Possible questions in the taxi data include whether pickup and drop-off locations are connected, how often people start trips at particular locations, what the typical trip distance is, whether passenger count relates to trip distance, how people pay, and whether payment type is connected to vendor ID.

Anna
The tutorial narrows those possibilities to four key questions: pickup-location frequency, the relationship between passenger count and trip distance, payment statistics, and the relationship between payment type and vendor ID.

Corey
And pivot tables are especially useful for answering them. A pivot table groups data according to selected fields and can calculate summaries such as counts, minimums, maximums, and averages. That makes large datasets easier to examine in a concise form.

Anna
Let's walk through the first pivot table: pickup-location frequency.

Corey
In Google Sheets, choose Insert and then Pivot table, and create it on a new sheet. In the pivot-table editor, add pickup location as the row field. That lists the different pickup locations. Then add pickup location ID as a value and set it to count, which tells us how many rides began at each location.

Anna
The results can then be copied to a separate sheet with headings such as pickup location and frequency.

Corey
Yes, and copy only the desired values rather than leaving them linked to the pivot table. That way, later changes to the pivot table will not alter the separate analysis sheet. Once the values are copied, sort the frequency column in descending order to identify the most popular pickup locations.

Anna
In the example, pickup location 237 was the most frequent, with 4,192 rides beginning there.

Corey
For the second question, clear the earlier pivot-table fields and add passenger count as the row field. Then add trip distance as a value, but change the calculation from count to average. This produces the average trip distance for each passenger-count category, including passenger counts from zero through six.

Anna
And, as before, that result is copied to a separate sheet, labeled with passenger count and trip distance, so it can be examined independently.

Corey
For the third question, investigate payment statistics. Use payment type as the row field and also add payment type as a value, setting the value calculation to count. The resulting table shows how frequently each payment type appears.

Anna
The fourth question is a comparison between two variables, so the pivot table needs both rows and columns.

Corey
Correct. Add payment type as the row field and vendor ID as the column field. Then count either vendor ID or payment type as the value; both produce the same counts for each combination. The resulting table has four rows for the four payment types and two columns for the two vendor types.

Anna
That makes it possible to see combinations that are present and combinations that are absent. In the example, vendor two had no records for payment types three and four.

Corey
Exactly. That is the value of exploratory analysis: it helps answer focused questions, compare categories, uncover patterns, and identify potential problems in the data.

Anna
So the full process moves from descriptive statistics to exploratory questions and then to pivot tables that organize the answers.

Corey
Yes. We used mean, median, minimum, and maximum to understand the fare data and find invalid negative values. Then we defined four questions and used pivot tables to summarize pickup frequency, average trip distance by passenger count, payment-type frequencies, and payment type by vendor ID.

Anna
And the next step after this initial exploration is data visualization, where those findings can be represented with graphs, charts, and other visual displays.

Ask anything
We've read this whole study set, so questions about it get the best answers.