idek what chapter Flashcards

1
Q

Series vs. DataFrames

A

series= 1d arrays
dataframes = 2d arrays
each of which have rows and columns which can be labelled

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

how to create series or dataframe

A

use python dictionary

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

define a dictionary

A

structure but mapping type (not a data sequence, so is indexed using keys)

is of type dict

mutable!

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

how to create a dictionary?

A

key-value pairs separated by commas, put in CURLY BRACKETS
bigguy = {‘keyname’:value_inside_key, ‘biggestguy’:’masonReilly}

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

how to index in a dictionary

A

dictionary[‘keyname’]
error if keyname DNE or index using integers

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

dictionary = mutable or not?

A

mutable (including modifying things inside it)

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

how to add/remove values to dictionary

A

dictionary[‘newkeyname’] = 123453241

del dictionary[‘nameofthingimremoving’]

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

len(mydictionary) returns?

A

amnt of key pairs

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

list(mydictionary) returns?
‘year’ in mydictionary returns?

A

returns the list equivalent
returns whether or not a key of that name exists in the dictionary

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

mydictionary = {‘year’:2313, ‘big’:’mason reilly’}
mydictionary.get(‘size’)
mydictionary.get(‘size’, -999)
mydictionary.get(‘big’}
what will these two getters return?

A
  1. None
  2. -999
  3. ‘mason reilly’
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

mydictionary.get()

A

mydictionary.get(‘keyname’)
mydictionary.get(‘keyname’, thing if keyname is not in dictionary)

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

why is get better than indexing a keyname?

A

indexing will return an error, get will return a value

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

dictionary pop

A

mydictionary.pop(‘name’)
mydictionary.pop(‘name’, thing if name DNE)

removes and returns removed value

error if no thing for DNE is specified and name DNE

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

dictionary popitem

A

mydict.popitem()
removes and returns last key of dictionary as a tuple

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

dictionary clear

A

mydict.clear()
clears all key-pairs from dictionary

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

keys
values
items

A

mydict.keys()
mydict.values()
mydict.items()

all used to iterate, returns VIEW OBJECTS of the certain things

keys returns a view object list of the names
values returns values list

items returns keys and values respectively, need 2 iterators to work with them

17
Q

how to store multiple dictionaries

A

list of dictionaries

18
Q

can you have data sequences inside of dictionaries?

19
Q

how would you do a dictionary comprehension?

A

mydict = {i:i**3 for i in range(5)}
each of these adds a new key-value pair

20
Q

do key names have to be strings?

21
Q

should you import pandas with numpy? why?

A

yes, bcz its built on nump-y

22
Q

What is a Pandas Series?

A

1d array created using a list or array

Stored as a NumPy array, can index it and slice it just like every other array

23
Q

what does this return:
numseries = pd.Series([11, 2, 3, 5])
numseries

A

0 11
1 2
2 3
3 5
dtype: int64
indices, actual data passed, AND dtype are stored in variable!

24
Q

how to access just the numbers in Series?

A

numseries.values
returns
array([11, 2, 3, 5])

25
values
numseries.values array([11, 2, 3, 5]) returns the non-index, non type, actual values stored in the Series.
26
can you use index on a series?
yes, but itll just give you the start index the end index and the steps between each index
27
create a series with indices a, b, c, d
mystuff = pd.Series([1, 2, 3, 4], ['a', 'b', 'c', 'd']) these new indices can be used to index and slice into the series numlabels['b':'d'] returns b 2 c 3 d 4 dtype int64
28
do specified indices work inclusively on all or like normal python?
inclusively on all, only the OG default integer indice slicing does not include the last index
29
can you make a series into a dictionary?
yes! typecast whatever dictionary you want and youll get the indexes as the names and the values as the values with the little dtype at the bottom
30
wtf is a DataFrame
2d array with labels for rows and columns
31
make a dataframe
dataf = pd.DataFrame(myseries, columns = ['name of first column'])
32