Pandas Strings Flashcards

1
Q

names.str.capitalize()

A

a single method that will capitalize all the entries, while skipping over any missing values

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

Using tab completion on this str attribute

A

will list all the vectorized string methods available to Pandas.

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

len() lower() translate() islower()

ljust() upper() startswith() isupper()

A

Methods similar to Python string methods

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

rjust() find() endswith() isnumeric()

center() rfind() isalnum() isdecimal()

A

Methods similar to Python string methods

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

zfill() index() isalpha() split()

strip() rindex() isdigit() rsplit()

A

Methods similar to Python string methods

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

rstrip() capitalize() isspace() partition()

lstrip() swapcase() istitle() rpartition()

A

Methods similar to Python string methods

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

match()

A

Call re.match() on each element, returning a boolean.

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

extract()

A

Call re.match() on each element, returning matched groups as strings.

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

findall()

A

Call re.findall() on each element

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

replace()

A

Replace occurrences of pattern with some other string

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

contains()

A

Call re.search() on each element, returning a boolean

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

count()

A

Count occurrences of pattern

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

split()

A

Count occurrences of pattern

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

rsplit()

A

Equivalent to str.rsplit(), but accepts regexps

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

get()

A

Index each element

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

slice()

A

Slice each element

17
Q

slice_replace()

A

Replace slice in each element with passed value

18
Q

cat()

A

Concatenate strings

19
Q

repeat()

A

Repeat values

20
Q

normalize()

A

Return Unicode form of string

21
Q

pad()

A

Add whitespace to left, right, or both sides of strings

22
Q

wrap()

A

Split long strings into lines with length less than a given width

23
Q

join()

A

Join strings in each element of the Series with passed separator

24
Q

get_dummies()

A

extract dummy variables as a dataframe

25
Q

df.str.slice(0, 3) is equivalent to

A

df.str[0:3]

26
Q

monte.str.split().str.get(-1)

A

to extract the last name of each entry, we can combine split() and get():

27
Q

recipes.ingredients.str.len().describe()

A

sample info getting

28
Q

recipes.name[np.argmax(recipes.ingredients.str.len())]

A

sample info getting

which recipe has the longest ingredient list

29
Q

recipes.description.str.contains(‘[Bb]reakfast’).sum()

A

how many of the recipes are for breakfast food

30
Q

recipes.ingredients.str.contains(‘[Cc]innamon’).sum()

A

cinnamon as an ingredient

31
Q

spice_list = [‘salt’, ‘pepper’, ‘oregano’, ‘sage’, ‘parsley’,
‘rosemary’, ‘tarragon’, ‘thyme’, ‘paprika’, ‘cumin’]

import re
spice_df = pd.DataFrame(dict((spice, recipes.ingredients.str.contains(spice, re.IGNORECASE))
for spice in spice_list))
spice_df.head()

A

search to see whether they are in each recipe’s ingredient list

return boolean data frame