Python Flashcards
Attribute that returns data type for a series or dataframe
Series.dtype
Dataframe.dtype
pandas method to show first n (5 is default) rows in a series
Series.head()
pandas method to show last n (5 is default) rows in a series
Series.tail()
pandas method to return unique values in a series
Series.unique()
pandas method to view the highest and lowest values in a series with their counts
Series.sort_index()with ascending=True orFalse
pandas method to count unique values in a series
Series.value_counts()
dropna=False includes null
normalize=True to do %
pandas method to remove/replace specified text
Series.str.replace([‘text_to_replace’],’’)
pandas method to cast a pandas object to a specified type (ex: cast string to float or int)
Series.astype(float)
pandas method chaining to replace text and cast to number
Series.str.replace([‘text_to_replace’],’’).astype(float)
pandas method to detect missing values and return a boolean same-sized object indicating if the values are NA.
Series.isnull()
Ex: Select null values in column
rev_is_null = f500[“revenue”].isnull()
pandas method to detect existing (non-missing) values and return a boolean same-sized object indicating if the values are not NA.
Series.notnull()
Ex: Select non-null values in a column
rev_not_null = f500[f500[“revenue”].notnull()
pandas method to generate descriptive statistics such as central tendency, dispersion and shape of a dataset’s distribution, excluding NaN values. Analyzes both numeric and object series, as well as DataFrame column sets of mixed data types. The output will vary depending on what is provided.
Series.describe()
include = ‘all’ to include non-numeric columns
pandas method to rename series index labels or name.
Series.rename({“ram”:”ram_gb”}, axis = ‘columns’, inplace = True)
pandas method to remove whitespace from start and end of string
String.strip()
pandas method to convert string to lowercase
String.lower()