pandas Flashcards

1
Q

import pandas library

A

import pandas as pd

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

create a series in pandas

A

s = pd.Series([2,3,4,3], index=[‘a’,’b’,’c’,’d’])

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

create a dataFrame in pandas

A

a = pd.DataFrame({‘a’ : [1,2,3], ‘b’ : [3,4,5]}, columns=[‘a’,’b’])

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

read in csv in panadas

A

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

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

write dataframe to csv file

A

df.to_csv(‘/filepath/file.csv’)

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

get value at a certain location given indices of row x col

A

a.iloc[[row], [col]]

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

get value at a certain location given index and column names

A

a.loc[[row_name],[col_name]]

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

Get values from series that are > 2

A

s[(s > 2)]

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

get values from series equal to 2 or 3

A

s[(s == 3) | (s ==4)]

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

get populations greater than 1million

A

df[df[‘population’] > 10000000]

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

set series index a = 5

A

s[‘a’] = 5

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

drop rows ‘a’ and ‘c’

A

s.drop([‘a’,’c’])

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

drop column ‘population’

A

s.drop(‘population’, axis=1)

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

sort the dataframe by population size

A

df.sort_values(by=’Population’)

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

rank matrix positions

A

df.rank()

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

get dataframe columns

A

df.columns

17
Q

get a sense of the dataframe with a single function – getting all count, mean, std, min, etc

A

df.describe()

18
Q

get rid of data that has null values

A

df.dropna(axis=0)