Pandas Flashcards
Learn the basics of Pandas
How to define your data frame from a csv file that is sitting in the same folder as your Python file?
df = pd.read_csv(“finename.csv”)
How to display the first 5 rows of your dataframe?
df.head(5)
How to display the last 5 rows of your dataframe?
df.tail(5)
How to save a dataframe to a specific format?
df.to_filetype(filename)
How to get the number of rows and columns of a dataframe?
df.shape
How to get the index, datatype and memory information of a dataframe?
df.info()
How to return a Series containing counts of unique values?
Series.value_counts()
How to generate descriptive statistics from a dataframe? (Descriptive statistics include those that summarize the central tendency, dispersion and shape of a dataset’s distribution, excluding NaN values)
df.describe()
df[‘column_name’].describe()
How to check data type?
df.dtypes
Ho to change data type?
astype()
Ex: astype(str) -> will tranform into a string
How to check missing value?
df.isnull().sum()
OR
df[df[‘column_name’].isnull()]
How to assign to a variable the content of a specific column?
df1 = df[“column_name”]
How to assign to a variable the content of several columns?
df1 = df[[“column_name1”, “column_name2”]]
How to delete column?
del df[“column_name”]
How to check the content of one column that is above a certain number?
df1 = df [(df [“column_name”] > 1500 ) ]
print df1