A DataFrame is an enhanced two-dimensional array. Like Series, DataFrames can have custom row and column indices, and offer additional operations and capabilities that make them more convenient for many data-science oriented tasks. DataFrames also support missing data. Each column in a DataFrame is...
Saturday, October 17, 2020
Friday, October 16, 2020
Creating a Series
We can specify custom indices with the index keyword argument:In [12]: grades = pd.Series([87, 100, 94], index=['Wally', 'Eva', 'Sam'])In [13]: gradesOut[13]:Wally 87Eva 100Sam 94dtype: int64In this case, we used string indices, but you can use other immutable types, including integers not beginning...
Thursday, October 15, 2020
Producing Descriptive Statistics for a Series
Series provides many methods for common tasks including producing various descriptive statistics. Here in this post we will see count, mean, min, max and std (standard deviation):In [6]: grades.count()Out[6]: 3In [7]: grades.mean()Out[7]: 93.66666666666667In [8]: grades.min()Out[8]: 87In [9]: grades.max()Out[9]:...
Wednesday, October 14, 2020
pandas Series and DataFrames
NumPy’s array is optimized for homogeneous numeric data that’s accessed via integer indices. Data science presents unique demands for which more customized data structures are required. Big data applications must support mixed data types, customized indexing, missing data, data that’s not structured...
Tuesday, October 13, 2020
Reshaping and Transposing
We’ve used array method reshape to produce two dimensional arrays from one-dimensional ranges. NumPy provides various other ways to reshape arrays.reshape vs. resizeThe array methods reshape and resize both enable you to change an array’s dimensions. Method reshape returns a view (shallow copy) of the...
Monday, October 12, 2020
Deep Copies
Though views are separate array objects, they save memory by sharing element data from other arrays. However, when sharing mutable values, sometimes it’s necessary to create a deep copy with independent copies of the original data. This is especially important in multi-core programming, where...
Sunday, October 11, 2020
Views: Shallow Copies
View objects are objects that “see” the data in other objects, rather than having their own copies of the data. Views are also known as shallow copies. Various array methods and slicing operations produce views of an array’s data.The array method view returns a new array object with a view of the original...
Saturday, October 10, 2020
Array-Oriented Programming with NumPy- 8 (Indexing and Slicing)
One-dimensional arrays can be indexed and sliced using the same syntax and techniques we use for Lists and Tuples”. Here, we focus on array-specific indexing and slicing capabilities.Indexing with Two-Dimensional arraysTo select an element in a two-dimensional array, specify a tuple containing the element’s...
Friday, October 9, 2020
Array-Oriented Programming with NumPy- 7 (NumPy Universal Functions)
NumPy offers dozens of standalone universal functions (or ufuncs) that perform various element-wise operations. Each performs its task using one or two array or array-like (such as lists) arguments. Some of these functions are called when you use operators like + and * on arrays. Each returns...
Thursday, October 8, 2020
Array-Oriented Programming with NumPy- 6 (NumPy Calculation Methods)
An array has various methods that perform calculations using its contents. By default, these methods ignore the array’s shape and use all the elements in the calculations. For example, calculating the mean of an array totals all of its elements regardless of its shape, then divides by the total number...
Wednesday, October 7, 2020
Array-Oriented Programming with NumPy- 5 (array Operators)
NumPy provides many operators which enable you to write simple expressions that perform operations on entire arrays. In this post, I am demonstrating arithmetic between arrays and numeric values and between arrays of the same shape.Arithmetic Operations with arrays and Individual Numeric ValuesFirst,...
Tuesday, October 6, 2020
Array-Oriented Programming with NumPy-4 (List vs. array Performance)
Most array operations execute significantly faster than corresponding list operations. To demonstrate, we’ll use the IPython %timeit magic command, which times the average duration of operations. Note that the times displayed on your system may vary from what we show here.Timing the Creation of...
Monday, October 5, 2020
Array-Oriented Programming with NumPy-3 (Filling arrays and creating arrays)
NumPy provides functions zeros, ones and full for creating arrays containing 0s, 1s or a specified value,respectively. By default, zeros and ones create arrays containing float64 values. We’ll show how to customize the element type momentarily. The first argument to these functions must be an integer...
Sunday, October 4, 2020
Array-Oriented Programming with NumPy-2 (array Attributes)
An array object provides attributes that enable you to discover information about its structure and contents. In this section we’ll use the following arrays:In [1]: import numpy as npIn [2]: integers = np.array([[1, 2, 3], [4, 5,6]])In [3]: integersOut[3]: array([[1, 2, 3],[4, 5, 6]]) In...
Saturday, October 3, 2020
Array-Oriented Programming with NumPy-1
The NumPy (Numerical Python) library first appeared in 2006 and is the preferred Python array implementation. It offers a high-performance, richly functional n-dimensional array type called ndarray, which from this point forward we’ll refer to by its synonym, array. NumPy is one of the many opensource...
Friday, October 2, 2020
Artificial Intelligence—at the Intersection of CS and Data Science
When a baby first opens its eyes, does it “see” its parent’s faces? Does it understand any notion of what a face is—or even what a simple shape is? Babies must “learn” the world around them. That’s what artificial intelligence (AI) is doing today. It’s looking at massive amounts of data and learning...
Thursday, October 1, 2020
Recommendation systems
Recommendation systems are another example of AI technology that has been weaved into our everyday lives. Amazon, YouTube, Netflix, LinkedIn, and Facebook all rely on recommendation technology and we don't even realize we are using it. Recommendation systems rely heavily on data and the more data that...