Pd Basics Flashcards
How to read a CSV using pandas?
Pd.read_csv(‘link’)
How to get the NUM of rows and columns?
Df.shape
How to get more specified information about the data frame for example index type
Df.info()
How to display the list of columns?
Df.columns
How to set a limit of columns to 85?
Pd.set_option(‘display.max_columns’,85)
How to print first 3 values?
Df.head(3)
How to print last 3 values?
Df.tail(3)
What is a data frame?
Data frame is a two dimensional array with additional functions
What is a series?
Series is a one dimensional array with additional functions
How would you print the first 3 elements using iloc where you want to return only column 2 as output
Df.iloc[[0,1,2],2] or df.iloc[0:3,2]
What’s the difference between loc and iloc
Iloc uses indices as columns loc uses their actual names
What does Inplace=True do?
Applies the change to the data frame
How would you change the index of a column with a different one?
Df.set_index(‘column’)
How would you reset the indices?
Df.reset_index()
How would you sort the indices?
Df.sort_index()
What is a filter mask? Give one example
A filter mask is a Boolean expression, if a row is True compared to this expression, it will be displayed. Filt = (df[‘cost’] == 0)
What do these signs mean: & |~
And or not
How to check if a series contains a certain value?
Df[column].isin()
How to check if a string contains a certain combination of signs? How to change a value from notanumber to false?
Df[column].str.contains(“”, na=false)
How would you change values for a column named email to lowercase
Df[email] = df[email].str.lower()
How does apply work?
Apply works on series by changing every single value one by one
Df.apply(pd.Series.min)
How does applymap works?
Applymap works like apply but not just for elements of series, for elements of dataframes.
Df.applymap(str.lower)
How does map work?
Map changes chosen values and lives everything else as NAN
Df[column].map({key:value})
How does replace work?
Replace changes chosen values and leaves other values as they were
Df[column].replace({key:value})