Pandas Flashcards
What is the accepted way to install NumPy?
import numpy as np
What is NumPy?
Used as a building block for a lot of other libraries. Strongly types data and uses C to make it very fast.
How would you import a csv into a NumPy array?
my_data = np.loadtxt( ‘data/sales-00.csv’ , delimiter = ‘ , ‘ )
Command for getting the shape of a NumPy array?
my_data.shape
Getting mean, standard deviation, min and max from NumPy array?
np. mean(my_data)
np. std(my_data)
np. min(my_data)
np. max(my_data)
What do the various axis refer to?
axis = 0 --- > rows axis = 1 ---> columns
What is the syntax for slicing an array?
array[ n:m ]
Where n is the starting index and m is the end index (not included).
When slicing an array, what is the syntax to slice from the beginning or to the end?
from beginning — my_array[ : 2]
from end — my_array[ 2: ]
What is a step function when slicing an array and what is its syntax?
It steps over items in list at specific interval,
This array starts at element 1, selects every other element until element 20.
my_array[ 1:20:2 ]
How can you find the index of an item in and array?
my_array.index( ‘cherries’ )
What is the syntax for creating an NymPy array?
np.arange( start, end, step)
np.arange(0, 10, 2)
this creates a NumPy array [0, 2, 4, 6, 8]
What is the syntax for creating a list of evenly spaced values in a NumPy array given a start and end and number of values desired?
np.linspace( start, end , number_of_values )
How can you quickly determine the number of dimensions of a NumPy array?
The number of square brackets at the beginning will show how many dimension the array has.
What is the syntax for importing pandas?
import pandas as pd
What is the difference between a NumPy array and a panda series?
A panda series is indexed with and index of our choosing.
Two syntaxes for creating a panda series with a labeled index.
my_data = [1, 2, 3]
my_index = [a, b, c]
pd.Series( data=my_data, index=my_index )
or using a dictionary:
my_data = {‘a’: 1, ‘b’: 2, ‘c’: 3}
pd.Series( my_data )
How to access a value from a panda series given it’s index label?
if eth index label is Emily:
my_array[‘Emily’]
How to slice a panda series using its index labels?
my_series[ ‘b’:’d’ ]
This will get the values from (and including) b, to (and including) d.
What is a panda dataframe?
Dataframes are tables of indexed columns, containing potentially different types of data.
Each column is pd.Series object.