Python Pandas Flashcards

1
Q

What are pandas in Python?

A

A data analysis and manipulation library.

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

How do you import pandas in Python?

A

import pandas as pd

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

What is a DataFrame in pandas?

A

A 2D labeled data structure with columns of potentially different types.

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

What is a Series in pandas?

A

A 1D labeled array capable of holding any data type.

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

How do you create a DataFrame from a dictionary?

A

pd.DataFrame({‘col1’: [1

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

How do you read a CSV file with pandas?

A

pd.read_csv(‘file.csv’)

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

How do you write a DataFrame to a CSV file?

A

df.to_csv(‘file.csv’

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

How do you display the first 5 rows of a DataFrame?

A

df.head()

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

How do you display the last 5 rows of a DataFrame?

A

df.tail()

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

How do you get DataFrame column names?

A

df.columns

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

How do you get DataFrame index values?

A

df.index

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

How do you get a quick summary of a DataFrame?

A

df.info()

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

How do you get statistical summary of numeric columns?

A

df.describe()

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

How do you select a single column from a DataFrame?

A

df[‘column_name’]

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

How do you select multiple columns from a DataFrame?

A

df[[‘col1’

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

How do you select rows by index?

A

df.loc[0] or df.iloc[0]

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

How do you filter rows by condition?

A

df[df[‘col’] > 10]

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

How do you add a new column to a DataFrame?

A

df[‘new_col’] = values

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

How do you drop a column from a DataFrame?

A

df.drop(‘col’

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

How do you drop a row from a DataFrame?

A

df.drop(index

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

How do you rename columns in a DataFrame?

A

df.rename(columns={‘old’: ‘new’}

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

How do you check for missing values?

A

df.isnull()

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

How do you fill missing values with 0?

A

df.fillna(0)

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

How do you drop rows with missing values?

A

df.dropna()

25
How do you sort a DataFrame by column?
df.sort_values('col')
26
How do you reset the index of a DataFrame?
df.reset_index(drop=True)
27
How do you set a column as the index?
df.set_index('col'
28
How do you group data by a column?
df.groupby('col')
29
How do you aggregate grouped data?
df.groupby('col').agg({'val': 'sum'})
30
How do you merge two DataFrames?
pd.merge(df1
31
How do you concatenate two DataFrames vertically?
pd.concat([df1
32
How do you concatenate two DataFrames horizontally?
pd.concat([df1
33
How do you pivot a DataFrame?
df.pivot(index='a'
34
How do you melt a DataFrame?
pd.melt(df
35
How do you check for duplicates?
df.duplicated()
36
How do you drop duplicates?
df.drop_duplicates()
37
How do you convert column to datetime?
pd.to_datetime(df['col'])
38
How do you extract year from datetime column?
df['col'].dt.year
39
How do you apply a function to a column?
df['col'].apply(func)
40
How do you map values in a column?
df['col'].map({'old': 'new'})
41
How do you convert a column to numeric?
pd.to_numeric(df['col']
42
How do you create a DataFrame from a list?
pd.DataFrame(data
43
How do you export a DataFrame to Excel?
df.to_excel('file.xlsx'
44
How do you read an Excel file?
pd.read_excel('file.xlsx')
45
How do you check data types of columns?
df.dtypes
46
How do you change data type of a column?
df['col'] = df['col'].astype('int')
47
How do you get the number of rows and columns?
df.shape
48
How do you count unique values in a column?
df['col'].nunique()
49
How do you get value counts in a column?
df['col'].value_counts()
50
How do you sample random rows from a DataFrame?
df.sample(n=5)
51
How do you get the memory usage of a DataFrame?
df.memory_usage()
52
How to read a CSV file?
employee_df = pd.read_csv('employee_information.csv')
53
How to import the pandas lib to Python?
Import pandas as pd
54
What is the key structure of pandas?
df (data frame)
55
How to create a data frame?
x = pd.df({Employe ID:[1,2,3,4]'})
56
How do I get a statistical summary?
x.describe() (you will get the mean,std,min,25%, 50%, 75%,max)
57
How to Normalize the data?
df['normalized'] = (df['col'] - df['col'].min()) / (df['col'].max() - df['col'].min())
58
What is MatLibplot?
59
What is sklearn?