pandas 1_4 Flashcards
(52 cards)
How do you write a multi-line string in Python?
””” wrap it in three quotes “””
(Python) How would you refer to the first element in a list named my_list?
my_list[0]
(Python) How would you refer to the last element in a list named my_list?
my_list[-1]
(Python) How would you refer to the first two elements in a list named my_list?
my_list[0:2]
(Python) What is a dict surrounded by?
curly brackets
(Python) How would you access 1 in my_dict = {‘a’: 1, ‘b’: 2}?
my_dict[‘a’]
(Python) How would you change ‘a’ to 0 in my_dict = {‘a’: 1, ‘b’: 2}?
my_dict[‘a’] = 0
(Python) How would you add a new item ‘c’ = 3 in my_dict = {‘a’: 1, ‘b’: 2}?
my_dict[‘c’] = 3
(Python) What does this code do?
for x in my_roster_list:
print(x)<br></br><br></br>
prints the values of my_roster_list<br></br>
(Python) What would type([x*2 for x in [1, 2, 3]) return?
list
(Python) What is [x*2 for x in [1, 2, 3]] called?
list comprehension
(Python) How would you turn mydict = {‘a’: 1, ‘b’: 2} into {‘A’: 2, ‘B’: 4} using a dict comprehension?
{key.upper(): value*2 for key, value in mydict.items()}
(Python) How would you turn mydict = {‘a’: 1, ‘b’: 2} into a list [1, 2] using list comprehensions?
[x for _, x in mydict.items()]
(Pandas) How would you print the first five rows of a DataFrame df?
df.head()
(Pandas) What is the function to load a csv into a DataFrame?
pd.read_csv()
(Pandas) What are the two main data structures Pandas gives you?
DataFrame, Series
(Pandas) What is the type of a single DataFrame column?
Series
(Pandas) What is the method to change the index on a DataFrame?
set_index
(Pandas) What is the default index on a DataFrame?
0, 1, 2, … for however many rows are in your data
(Pandas) What is the method to output a DataFrame to a csv?
to_csv
(Pandas) Why do you need the inplace=True argument to make permanent changes to DataFrames via methods?
because otherwise most methods only return a copy of the DataFrame and leave the original untouched
(Pandas) How would you add a column named ‘pts_per_td’ that always equaled 6 to a DataFrame named df?
df[‘pts_per_td’] = 6
(Pandas) What is the name of the method that lets you use functions like upper and replace on your string columns?
str
(Pandas) How do you write ‘or’ when creating boolean columns in Pandas?
|