Pandas Flashcards

Learn the basics of Pandas

1
Q

How to define your data frame from a csv file that is sitting in the same folder as your Python file?

A

df = pd.read_csv(“finename.csv”)

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

How to display the first 5 rows of your dataframe?

A

df.head(5)

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

How to display the last 5 rows of your dataframe?

A

df.tail(5)

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

How to save a dataframe to a specific format?

A

df.to_filetype(filename)

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

How to get the number of rows and columns of a dataframe?

A

df.shape

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

How to get the index, datatype and memory information of a dataframe?

A

df.info()

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

How to return a Series containing counts of unique values?

A

Series.value_counts()

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

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)

A

df.describe()
df[‘column_name’].describe()

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

How to check data type?

A

df.dtypes

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

Ho to change data type?

A

astype()
Ex: astype(str) -> will tranform into a string

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

How to check missing value?

A

df.isnull().sum()
OR
df[df[‘column_name’].isnull()]

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

How to assign to a variable the content of a specific column?

A

df1 = df[“column_name”]

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

How to assign to a variable the content of several columns?

A

df1 = df[[“column_name1”, “column_name2”]]

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

How to delete column?

A

del df[“column_name”]

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

How to check the content of one column that is above a certain number?

A

df1 = df [(df [“column_name”] > 1500 ) ]
print df1

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

What is the argument “index_col” of the pandas read_csv function used for?

A

You can specify which column to use as the left index for the rows.
df1 = pd.read_csv(“ToshlExpenses - Toshl Dépenses.csv”, index_col=”Expense\nin Euro”)
df1

17
Q

How to replace Null values in dataframe?

A

df.fillna()

18
Q

How to analyze a dataframe and drop Rows/Columns with Null values?

A

df.dropna()