Pandas Flashcards

1
Q

series

A

array with index

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

Example: create a series

A

obj = Series([4, 7, -5, 3], index = [‘d’, ‘b’, ‘a’, ‘c’])

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

find obj value

A

obj.values

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

find obj index

A

obj.index

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

Find value for index ‘a’ and index ‘c’,’a’,’d’

A
  1. obj[‘a’]

2. obj[[‘c’, ‘a’, ‘d’]]

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

Series vs. dict

A

Series is a fixed-length, ordered dict

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

Check if index ‘b’ exists in obj

A

‘b’ in obj

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

Create series from dict sdata

A

obj = Series (sdata)

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

Check if the value exits (or not exits) for the series obj

A
  1. pd.isnull(obj)

2. pd.notnull(obj)

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

Create name attributes for Series object obj and its index

A
  1. obj.name = ‘population’

2. obj.index.name = ‘state’

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

Most common ways to construct DataFrame

A
  1. from a dict of equal-length lists e.g. if data is a dict object, then DataFrame object frame = DataFrame(data)
  2. NumPy arrays, e.g. if data is a NumPy array, DataFrame(data, columns=[‘year’, ‘state’, ‘pop’]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to retrieve a column from DataFrame as a Series

A
  1. dict-like notation: frame[‘state’]

2. by attribute. frame.year

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

retrieve a row from DAta Frame object frame with index ‘three’

A

frame.ix[‘three’]

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

delete a column ‘eastern’ from DataFrame object frame

A

del frame[‘eastern’]

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

Is the index objects mutable?

A

No, so Index objects c an be safely shared among data structures

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

create an Index object

A

index =- pd.Index(np.arrange(3))

17
Q

Class: Int64Index

A

Specialized Index for integer values

18
Q

Class: MultiIndex

A

“Hierarchical” index object representing multiple levels of indexing on a single axis

19
Q

Class: DatetimeIndex

A

Stores nanosecond timestamps (represented using NumPy’s datatime64 dtype)

20
Q

Class: PeriodIndex

A

Specialized Index for Period data (timespans)

21
Q

Index methods

A

append, diff, intersection, union, isin, delete, drop, insert, is_monotonic, is_unique, unique

22
Q

reindex

A

Crate a new object with the data conformed to a new index. e.g. obj2 = obj.reindex([‘a’, ‘b’, ‘c’, ‘d’, ‘e’], fill_value=0)

23
Q

forward fill when reindexing

A

ffill or pad; obj3.reindex(range(6), method = ‘ffill’)

24
Q

backward fill when reindexing

A

bfill or backfill

25
Q

Drop entry (1) ‘c’ (2) ‘d’ and ‘c’

A

obj. drop(‘c’)

obj. drop([‘d’, ‘c’])

26
Q

special indexing field ix

A

Select a subset of the rows and columns from a DataFrame with NumPy like notation plus axis labels

27
Q

Hierarchical indexing

A

Enable you to have multiple index levels on an axis