Business Analytics - Python Flashcards (Numpy and Pandas)

studied byStudied by 1 person
0.0(0)
Get a hint
Hint

import numpy as np

1 / 135

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

136 Terms

1

import numpy as np

Import convention for Numpy

New cards
2

np.zeroes(())

Create an array of zeroes

New cards
3

np.ones

Create an array of ones

New cards
4

np.arrange(10,25,5)

Create an array of evenly spaced values (step value_

New cards
5

np.linspace(0,2,9)

Create an array of evenly spaced values

New cards
6

np.full((2,2),7)

Create a constant array

New cards
7

np.eye(2)

Create a 2×2 identity matrix

New cards
8

np.random.random((2,2))

Create an array with random values

New cards
9

np.empty((3,2))

Create an empty array

New cards
10

np.int64

Signed 64-bit integer types

New cards
11

np.float32

Standard double-precision floating point

New cards
12

np.complex

Complex numbers represented by 128 floats

New cards
13

np.bool

Boolean type storing TRUE and FALSE values

New cards
14

np.object

Python object type

New cards
15
New cards
16

np.string_

Fixed-length string type

New cards
17

np.unicode_

Fixed-length unicode type

New cards
18

a.shape

Array dimensions

New cards
19

len(a)

Length of array

New cards
20

b.ndim

Number of array dimensions

New cards
21

e.size

Number of array elements

New cards
22

b.dtype

Data type of array elements

New cards
23

b.dtype.name

Name of data type

New cards
24

b.astype(int)

Convert an array to a different type

New cards
25

np.subtract(a,b)

Subtraction

New cards
26

np.add(b,a)

Addition

New cards
27

np.divide(a,b)

Division

New cards
28

np.multiply(a,b)

Multiplication

New cards
29

np.exp(b)

Exponentiation

New cards
30

np.sqrt(b)

Square root

New cards
31

np.sin(a)

Print sines of an array

New cards
32

np.cos(b)

Element-wise cosine

New cards
33

np.log(a)

Element-wise natural logarithm

New cards
34

e.dot(f)

Dot product

New cards
35
New cards
36

a == b

Element-wise comparison

New cards
37

np.array_equal(a, b)

Array-wise comparison

New cards
38

a.sum()

Array-wise sum

New cards
39

a.min()

Array-wise minimum value

New cards
40

b.max(axis=0)

Maximum value of an array row

New cards
41

b.cumsum(axis=1)

Cumulative sum of the elements

New cards
42

a.mean()

Mean

New cards
43

b.median()

Median

New cards
44

a.corrcoef()

Correlation coefficient

New cards
45

np.std(b)

Standard deviation

New cards
46

h = a.view()

Create a view of the array with the same data

New cards
47

np.copy(a)

Create a copy of the array

New cards
48

h = a.copy()

Create a deep copy of the array

New cards
49

a.sort()

Sort an array

New cards
50

c.sort(axis=0)

Sort the elements of an array's axis

New cards
51

a[2]

Select the element at the 2nd index

New cards
52

b[1,2]

Select the element at row 1 column 2

New cards
53

a[0:2]

Select items at index 0 and 1

New cards
54

b[0:2,1]

Select items at rows 0 and 1 in column 1

New cards
55
New cards
56

b[:1]

Select all items at row 0

New cards
57

a[ : :-1]

Reversed array a

New cards
58

a[a<2]

Select elements from a less than 2

New cards
59

b[[1, 0, 1, 0],[0, 1, 2, 0]]

Select elements (1,0),(0,1),(1,2) and (0,0)

New cards
60

b[[1, 0, 1, 0]][:,[0,1,2,0]]

Select a subset of the matrix’s rows and columns

New cards
61

i = np.transpose(b) or i.T

Permute array dimensions

New cards
62

b.ravel()

Flatten the array

New cards
63

g.reshape(3,-2)

Reshape, but don’t change data

New cards
64

h.resize((2,6))

Return a new array with shape (2,6)

New cards
65

np.append(h,g)

Append items to an array

New cards
66

np.insert(a, 1, 5)

Insert items in an array

New cards
67

np.delete(a,[1])

Delete items from an array

New cards
68

np.concatenate((a,d),axis=0)

Concatenate arrays

New cards
69

np.vstack((a,b))

Stack arrays vertically (row-wise)

New cards
70

np.r_[e,f]

Stack arrays vertically (row-wise)

New cards
71

np.hstack((e,f))

Stack arrays horizontally (column-wise)

New cards
72

np.column_stack((a,d)) or np.c_[a,d]

Create stacked column-wise arrays

New cards
73

np.hsplit(a,3)

Split the array horizontally at the 3rd index

New cards
74

np.vsplit(c,2)

Split the array vertically at the 2nd index

New cards
75

df = pd.DataFrame(

{"a" : [4 ,5, 6],

"b" : [7, 8, 9],

"c" : [10, 11, 12]},

index = [1, 2, 3])

Specify values for each column

New cards
76

df = pd.DataFrame(

[[4, 7, 10],

[5, 8, 11],

[6, 9, 12]],

index=[1, 2, 3],

columns=['a', 'b', 'c'])

Specify values for each row

New cards
77

df = pd.DataFrame(

{"a" : [4 ,5, 6],

"b" : [7, 8, 9],

"c" : [10, 11, 12]},

index = pd.MultiIndex.from_tuples(

[('d',1),('d',2),('e',2)],

names=['n','v'])))

Create DataFrame with a MultiIndex

New cards
78

pd.melt(df)

Gather columns into rows

New cards
79

pd.concat([df1,df2])

Append rows of DataFrames

New cards
80

df.pivot(columns='var', values='val')

Spread rows into columns

New cards
81

pd.concat([df1,df2], axis=1)

Append columns of DataFrames

New cards
82

df[df.Length > 7]

Extract rows that meet logical criteria.

New cards
83

df.drop_duplicates()

Remove duplicate rows (only considers columns)

New cards
84

df.head(n)

Select first n rows.

New cards
85

df.tail(n)

Select last n rows.

New cards
86

df.sample(frac=0.5)

Randomly select fraction of rows.

New cards
87

df.sample(n=10)

Randomly select n rows.

New cards
88

df.iloc[10:20]

Select rows by position

New cards
89

df.nlargest(n, 'value')

Select and order top n entries.

New cards
90

df.nsmallest(n, 'value')

Select and order bottom n entries.

New cards
91

df[['width','length','species']]

Select multiple columns with specific names.

New cards
92

df['width'] or df.width

Select single column with specific name.

New cards
93

df.filter(regex='regex')

Select columns whose name matches regular expression regex

New cards
94

df.loc[:,'x2':'x4']

Select all columns between x2 and x4 (inclusive).

New cards
95

df.iloc[:,[1,2,5]]

Select columns in positions 1, 2 and 5 (first column is 0).

New cards
96

df.loc[df['a'] > 10, ['a','c']]

Select rows meeting logical condition, and only the specific columns .

New cards
97

df['w'].value_counts()

Count number of rows with each unique value of variable

New cards
98

len(df)

# of rows in DataFrame

New cards
99

df['w'].nunique()

df.describe()

New cards
100

sum()

Sum values of each object.

New cards

Explore top notes

note Note
studied byStudied by 9 people
... ago
5.0(1)
note Note
studied byStudied by 10 people
... ago
5.0(1)
note Note
studied byStudied by 14 people
... ago
5.0(1)
note Note
studied byStudied by 18 people
... ago
5.0(1)
note Note
studied byStudied by 197 people
... ago
5.0(9)
note Note
studied byStudied by 32 people
... ago
5.0(1)
note Note
studied byStudied by 27 people
... ago
5.0(3)
note Note
studied byStudied by 1611 people
... ago
5.0(6)

Explore top flashcards

flashcards Flashcard (32)
studied byStudied by 29 people
... ago
5.0(1)
flashcards Flashcard (62)
studied byStudied by 4 people
... ago
5.0(1)
flashcards Flashcard (82)
studied byStudied by 23 people
... ago
5.0(1)
flashcards Flashcard (62)
studied byStudied by 8 people
... ago
4.0(1)
flashcards Flashcard (39)
studied byStudied by 5 people
... ago
5.0(1)
flashcards Flashcard (26)
studied byStudied by 13 people
... ago
5.0(1)
flashcards Flashcard (65)
studied byStudied by 6 people
... ago
5.0(1)
flashcards Flashcard (27)
studied byStudied by 229 people
... ago
5.0(2)
robot