Module 4 Flashcards

1
Q

List all the built in data types in python

A

Integers - int
Floating-point numbers - float
Strings - str
Booleans -bool
Lists - list
Tuples - tuple
Sets - set
Dictionaries - dict

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

what data type is this ?

age = 6
type(age)

A

int

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

age = 6.0
type(age)

what data type ?

A

float

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

which value cannot be converted to any other type other than a float ?

A

NaN

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

What is NoneType ?

A

NoneType is its own type, with only one possible value, None.

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

which type has two values: True and False.

A

Boolean

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

name_of_bed_monster = ‘Mike Wazowski’
name_of_bed_monster

Which DT is this ?

A

string

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

If the string contains quotation marks or apostrophes, how do we declare those strings in python ?

A

we can use double quotes or triple single quotes, or triple-double quotes to define the string.

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

len()

A

returns the length of the string

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

.upper()

A

converts into upper case

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

.lower()

A

converts into lower case

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

count()

A

We can also count the number of times a substring or character is present in a string with .count().

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

float(‘five’)

output ?

A

ValueError: could not convert string to float: ‘five’

Detailed traceback:
File “<string>", line 1, in <module></module></string>

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

float(None)

output ?

A

TypeError: float() argument must be a string or a number, not ‘NoneType’

Detailed traceback:
File “<string>", line 1, in <module></module></string>

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

sentence = “I always lose at least one sock when I do laundry.”
words = sentence.split()
words

output ?

A

[‘I’, ‘always’, ‘lose’, ‘at’, ‘least’, ‘one’, ‘sock’, ‘when’, ‘I’, ‘do’, ‘laundry.’]

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

sentence = “I always lose at least one sock when I do laundry.” sentence.split(“e”)

output ?

A

This argument uses the character “e” to separate the string and discards the separator.

[‘I always los’, ‘ at l’, ‘ast on’, ‘ sock wh’, ‘n I do laundry.’]

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

What type of elements are present in a List ?

A

The elements in a list can be any objects, and they don’t all need to have the same type.

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

lists_of_lists = [[1,2], [‘buckle’, ‘My’, ‘Shoe’], 3, 4]
lists_of_lists

output ?

A

4

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

Lists vs strings

A

Lists are mutable whereas strings are not

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

append() ?

A

adds new item to end of list

21
Q

List down some verbs in regards to lists in python

A

max, sum, append

22
Q

What is difference between lists and tuples ?

A

They are represented with parentheses instead of square brackets, and
They are immutable

23
Q

Difference between sets and lists and tuple ?

A

They are unordered, meaning there is no element 0 and element 1, and
The values contained are unique - meaning there are no duplicate entries.

24
Q

Which verb can be used to add elements into a Set ?

25
What is a dictionary ?
A dictionary is a map between key-value pairs.
26
Can we change dictionary values ? If so, why ?
And since dictionaries are mutable, we can change the values.
27
how can we add values to a dictionary ?
using a new key name.
28
What kind of data types can the dictionary keys represent ?
Keys are not limited to strings and can be many different data types, including numerical values and tuples (but they cannot be dictionaries or lists).
29
How can you access all the key-value pairs in a dictionary ?
We can access all of the key-value pairs in a dictionary with the verb .items().
30
What is a panda series ?
A pandas Series is a one-dimensional array of values with an axis label, sort of like a list with a name attached to it.
31
how can you find the dtype of a df column ?
We can use the noun .dtypes to find the dtype of a column.
32
what are dtypes ?
columns in a Pandas dataframe have types called dtypes.
33
dtype('O') What does O stand for ?
Object
34
'The monster under my bed' * 3 Output ?
'The monster under my bedThe monster under my bedThe monster under my bed'
35
'The monster under my bed' + 1200 output ?
TypeError: can only concatenate str (not "int") to str Detailed traceback: File "", line 1, in
36
'The monster under my bed' + str(1200) Output ?
'The monster under my bed1200'
37
What happens if we add lists ?
If we add lists, similarly to strings, the lists concatenate together to create a single list containing the elements of both lists.
38
How can a list support subtraction and multiplication ?
subtraction and multiplication, are not supported when working with lists.
39
If we have these columns in a df, which of these columns will show up when we call .describe () ? name object mfr_type object calories object protein int64 fiber float64 fat int64 carbo float64 rating float64 hot bool dtype: object
only numerical columns, not objects
40
which method needs to be used to convert the string column "calories" into an int column ?
cereal['calories'].astype('int')
41
cereal = cereal.assign(calories=cereal['calories'].astype('int')) Whaat is going on here ?
We are using the assign verb to cast and assign the calories column
42
How can you calculate the mean for the "hot" column of the "cereal" DF ?
cereal['hot'].mean()
43
cereal.loc[:, 'protein': 'carbo'].sum(axis=1) What is going on here ?
calculating the sum of each row from protien till carbo
44
axis=1 meaning ?
refers to the calculation being done for each row, across multiple columns,
45
axis = 0 meaning ?
(which is the default for aggregation verbs) refers to the calculation for each column across multiple rows.
46
cereal = cereal.assign(total_pffc=cereal.loc[:, 'protein': 'carbo'].sum(axis=1))
calculating the sum and also assigning the sum value into a separate column
47
new = cereal_amended['mfr_type'].str.split('-', expand=True)
splitting a column
48
new = cereal_amended['mfr_type'].str.split('-', expand=False)
Our output is now a Pandas Series data type with a list containing both column values as the Series values.