Business Analytics - Python Flashcards (Numpy and Pandas)

0.0(0)
studied byStudied by 1 person
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/135

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

136 Terms

1
New cards

import numpy as np

Import convention for Numpy

2
New cards

np.zeroes(())

Create an array of zeroes

3
New cards

np.ones

Create an array of ones

4
New cards

np.arrange(10,25,5)

Create an array of evenly spaced values (step value_

5
New cards

np.linspace(0,2,9)

Create an array of evenly spaced values

6
New cards

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

Create a constant array

7
New cards

np.eye(2)

Create a 2×2 identity matrix

8
New cards

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

Create an array with random values

9
New cards

np.empty((3,2))

Create an empty array

10
New cards

np.int64

Signed 64-bit integer types

11
New cards

np.float32

Standard double-precision floating point

12
New cards

np.complex

Complex numbers represented by 128 floats

13
New cards

np.bool

Boolean type storing TRUE and FALSE values

14
New cards

np.object

Python object type

15
New cards
16
New cards

np.string_

Fixed-length string type

17
New cards

np.unicode_

Fixed-length unicode type

18
New cards

a.shape

Array dimensions

19
New cards

len(a)

Length of array

20
New cards

b.ndim

Number of array dimensions

21
New cards

e.size

Number of array elements

22
New cards

b.dtype

Data type of array elements

23
New cards

b.dtype.name

Name of data type

24
New cards

b.astype(int)

Convert an array to a different type

25
New cards

np.subtract(a,b)

Subtraction

26
New cards

np.add(b,a)

Addition

27
New cards

np.divide(a,b)

Division

28
New cards

np.multiply(a,b)

Multiplication

29
New cards

np.exp(b)

Exponentiation

30
New cards

np.sqrt(b)

Square root

31
New cards

np.sin(a)

Print sines of an array

32
New cards

np.cos(b)

Element-wise cosine

33
New cards

np.log(a)

Element-wise natural logarithm

34
New cards

e.dot(f)

Dot product

35
New cards
36
New cards

a == b

Element-wise comparison

37
New cards

np.array_equal(a, b)

Array-wise comparison

38
New cards

a.sum()

Array-wise sum

39
New cards

a.min()

Array-wise minimum value

40
New cards

b.max(axis=0)

Maximum value of an array row

41
New cards

b.cumsum(axis=1)

Cumulative sum of the elements

42
New cards

a.mean()

Mean

43
New cards

b.median()

Median

44
New cards

a.corrcoef()

Correlation coefficient

45
New cards

np.std(b)

Standard deviation

46
New cards

h = a.view()

Create a view of the array with the same data

47
New cards

np.copy(a)

Create a copy of the array

48
New cards

h = a.copy()

Create a deep copy of the array

49
New cards

a.sort()

Sort an array

50
New cards

c.sort(axis=0)

Sort the elements of an array's axis

51
New cards

a[2]

Select the element at the 2nd index

52
New cards

b[1,2]

Select the element at row 1 column 2

53
New cards

a[0:2]

Select items at index 0 and 1

54
New cards

b[0:2,1]

Select items at rows 0 and 1 in column 1

55
New cards
56
New cards

b[:1]

Select all items at row 0

57
New cards

a[ : :-1]

Reversed array a

58
New cards

a[a<2]

Select elements from a less than 2

59
New cards

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

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

60
New cards

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

Select a subset of the matrix’s rows and columns

61
New cards

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

Permute array dimensions

62
New cards

b.ravel()

Flatten the array

63
New cards

g.reshape(3,-2)

Reshape, but don’t change data

64
New cards

h.resize((2,6))

Return a new array with shape (2,6)

65
New cards

np.append(h,g)

Append items to an array

66
New cards

np.insert(a, 1, 5)

Insert items in an array

67
New cards

np.delete(a,[1])

Delete items from an array

68
New cards

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

Concatenate arrays

69
New cards

np.vstack((a,b))

Stack arrays vertically (row-wise)

70
New cards

np.r_[e,f]

Stack arrays vertically (row-wise)

71
New cards

np.hstack((e,f))

Stack arrays horizontally (column-wise)

72
New cards

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

Create stacked column-wise arrays

73
New cards

np.hsplit(a,3)

Split the array horizontally at the 3rd index

74
New cards

np.vsplit(c,2)

Split the array vertically at the 2nd index

75
New cards

df = pd.DataFrame(

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

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

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

index = [1, 2, 3])

Specify values for each column

76
New cards

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

77
New cards

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

78
New cards

pd.melt(df)

Gather columns into rows

79
New cards

pd.concat([df1,df2])

Append rows of DataFrames

80
New cards

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

Spread rows into columns

81
New cards

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

Append columns of DataFrames

82
New cards

df[df.Length > 7]

Extract rows that meet logical criteria.

83
New cards

df.drop_duplicates()

Remove duplicate rows (only considers columns)

84
New cards

df.head(n)

Select first n rows.

85
New cards

df.tail(n)

Select last n rows.

86
New cards

df.sample(frac=0.5)

Randomly select fraction of rows.

87
New cards

df.sample(n=10)

Randomly select n rows.

88
New cards

df.iloc[10:20]

Select rows by position

89
New cards

df.nlargest(n, 'value')

Select and order top n entries.

90
New cards

df.nsmallest(n, 'value')

Select and order bottom n entries.

91
New cards

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

Select multiple columns with specific names.

92
New cards

df['width'] or df.width

Select single column with specific name.

93
New cards

df.filter(regex='regex')

Select columns whose name matches regular expression regex

94
New cards

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

Select all columns between x2 and x4 (inclusive).

95
New cards

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

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

96
New cards

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

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

97
New cards

df['w'].value_counts()

Count number of rows with each unique value of variable

98
New cards

len(df)

# of rows in DataFrame

99
New cards

df['w'].nunique()

df.describe()

100
New cards

sum()

Sum values of each object.