Introduction to Python ProgrammingXYZ Homework Edition

⇩ Download ▾

15.6 Summary

Highlights from this chapter include:

At this point, you should be able to write programs to create data structures to store different datasets and explore and visualize datasets.

Table 15.13 Chapter 15 reference.
FunctionDescription
np.array()Creates an ndarray from a list or tuple.
np.zeros()Creates an array of zeros.
np.ones()Creates an array of ones.
np.random.rand(n, m)Creates an array of random numbers with n rows and m columns
np.genfromtxt('data.csv', delimiter=',')Creates an array from a CSV file.
pd.DataFrame()Creates a DataFrame from a list, dictionary, or an array.
pd.read_csv()Creates a DataFrame from a CSV file.
df.head()Returns the first few rows of a DataFrame.
df.tail()Returns the last few rows of a DataFrame.
df.info()Provides a summary of the DataFrame, including the column names, data types, and the number of non-Null values.
df.describe()Generates the column count, mean, standard deviation, minimum, maximum, and quartiles.
df.value_counts()Counts the occurrences of unique values in a column and presents them in descending order.
df.unique()Returns an array of unique values in a column.
loc[]Allows for accessing data in a DataFrame using row/column labels.
iloc[]Allows for accessing data in a DataFrame using row/column integer-based indexes.
df[condition]Selects only the rows that meet the given condition.
df.loc[start_row:end_row, start_column:end_column]Slices using label ranges.
df.loc[[label1, label2, ...], :]Slices rows that are in the list [label1, label2, ...].
df.isnull()Returns a Boolean array with Boolean values representing whether each entry has been Null.
fillna()Replaces Null values.
dropna()Removes all rows containing a Null value.
plt.bar(x, height)Takes in two inputs, x and height, and plots bars for each x value with the height given in the height variable.
plt.plot(x, y)Takes in two inputs, x and y, and plots lines connecting pairs of (x, y) values.
plt.scatter(x, y)Takes in two inputs, x and y, and plots points representing (x, y) pairs.
plt.hist(x)Takes in one input, x, and plots a histogram of values in x to show distribution or trend.
plt.boxplot(x)Takes in one input, x, and represents minimum, maximum, first, second, and third quartiles, as well as outliers in x.

Adapted from Introduction to Python Programming by OpenStax (openstax.org), licensed under CC BY-NC-SA 4.0. Changes were made. License: CC-BY-NC-SA-4.0.

These eBooks are a prerelease and are not yet certified conformant with WCAG 2.1 AA or any other accessibility standard. Every page is built against an automated accessibility gate, and our target for the published editions is WCAG 2.2 Level AA. If something is unusable, please tell us.