concept Dask in category dask

appears as: Dask
Data Science with Python and Dask

This is an excerpt from Manning's book Data Science with Python and Dask.

To run the code notebooks and follow along with the examples in Data Science with Python and Dask, you should have the following software installed on your system:

Figure 6.1 The Data Science with Python and Dask workflow

c06_01.eps

We’ll now turn our attention to my favorite part of any data science project—exploratory data analysis. The goals of exploratory data analysis are to understand the “shape” of your data, find interesting patterns and correlations in your dataset, and identify significant relationships in your dataset that could be useful for predicting your target variable. As with the previous chapter, we’ll highlight the differences and special considerations necessary to perform data analysis in the distributed paradigm of Dask.

Once these two lines finish executing (which took about 45 minutes on my system), we’ll be in good shape to calculate the descriptive statistics more quickly and efficiently. For convenience, Dask provides built-in descriptive statistics functions so you don’t have to write your own algorithms. We’ll take a look at the five descriptive statistics we covered earlier in the section: mean, standard deviation, minimum, maximum, and skewness.

Listing 6.6 Calculating descriptive statistics
from dask.array import stats as dask_stats
with ProgressBar():
    mean = nyc_data_with_vehicle_age['Vehicle Age'].mean().compute()
    stdev = nyc_data_with_vehicle_age['Vehicle Age'].std().compute()
    minimum = nyc_data_with_vehicle_age['Vehicle Age'].min().compute()
    maximum = nyc_data_with_vehicle_age['Vehicle Age'].max().compute()
    skewness = float(dask_stats.skew(nyc_data_with_vehicle_age['Vehicle Age'].values).compute())    #1  

#1   Compute the skewness by feeding the Vehicle Age column into the dask_stats.skew function, and cast the result to a float.

As you can see in listing 6.6, for the mean, standard deviation, minimum, and maximum, you can simply call them as built-in methods of the Vehicle Age series. The exception to the set is calculating the skewness. There is no skew method as you might expect. However, Dask contains a myriad of statistical tests in the dask.array package, which we haven’t yet explored (chapter 9 is a deep dive into Dask Array functions). To calculate the skewness for this example, we must convert Vehicle Age from a Dask Series object to a Dask Array object, since the skew function from dask.array requires a Dask Array as input. To do this, we can simply use the values attribute of the Vehicle Age series. We can then feed that into the skew function to calculate the skewness. Inspecting the results of our calculations, we find the values listed in table 6.1.