DA (Python) Flashcards

1
Q

Mean (Pandas)
All Means
Mean for a column

A

df.mean()
df[‘a’].mean()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Mode (Pandas)
all Modes
Mode for a column

A

df.mode()
df[‘a’].mode()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Median (Pandas)
all Medians
Median for a column

A

df.median()
df[‘a’].median()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Standard Deviation (Pandas)
all Standard Deviations
Standard Deviation for a column

A

df.std()
df[‘a’].std()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Load data

A

import pandas as pd

df = pd.read_csv(‘SeaLevels.csv’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Read data

A

df.head()

First 5 rows

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

dealing with duplicates

A

z = [1,2,3,1,4,5,1]
seen = set()
cz = [x for x in z if not (x in seen or seen.add(x))]
print (cz)

[1,2,3,4,5]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Slices

A

Ranges from a list

myList = [1,2,3,4,5]
print(myList[:3]) - up to third
print(myList[1:]) - from 1 onwards
print(myList[2:4]) - from 3 to 4

[1, 2, 3]
[2, 3, 4, 5]
[3, 4]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Creating a dataframe

A

N = [‘Jack’, ‘Jill’, ‘John’]
H = [180, 170, 200]
S = [9, 5, 8]

df = pd.DataFrame({‘N’: N, ‘H’: H, ‘S’: S})

print(df)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

loop code

A

myList = [1,2,3,4,5,6]
sum = 0.0
for item in myList:
sum = sum + item
print(sum)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

built in functions

A

print(np.max(z))
print(np.min(z))
print(np.sum(z))
print(np.mean(z))
print(np.median(z))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

conditional selection

A

e = df[(df[‘N’] != ‘Jack’ ) & (df[‘H’] > 170)]

print(e)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

function

A

def MULT_of_3(num):
return num % 3 == 0

mO3 = [num for num in multList if MULT_of_3(num)]

print(“Multiples of 3 in the list:”, mO3)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Drop nulls

A

completeRows = df.dropna()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  • Select the 2nd and 3rd shoe size
  • Select 1st and 2nd Name
  • Find the mean height
  • Find the max height
  • Find the min shoe size
  • Find the median shoe size
A

multList = [4,3,6,7,43,56,453,67,544,322,37,87,77,79,36,25,320]

print(multList[1:3])
print(multList[0:2])
print(np.mean(multList))
print(np.max(multList))
print(np.min(multList))
print(np.median(multList))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Drop duplicates

A

cleaned = completeRows.drop_duplicates(subset=[‘N’,’H’,’A’,’B’,’S’])
print(cleaned)

15
Q

groupby

A

mean = df.groupby(‘a’)[‘Shoe Size’].mean()

16
Q

Standard Deviation (Code)

A

df.std()
std = df.[‘Shoe Size’].std()

17
Q

Correlation (Python)

A

correlation = df.corr()
correlation = df.[[‘column A’, ‘Column B’]].corr()