Pandas Flashcards

1
Q

Write the code that is required to run pandas

A

import pandas as pd

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

Read in a csv file into pandas given

import pandas as pd

A

pd.read_csv(‘myfile.csv’)

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

Read in a excel file into pandas given

import pandas as pd

A

pd.read_excel(‘my_file.xlsx’)

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

Read in a json file into pandas given

import pandas as pd

A

pd.read_json(‘my_file.json’)

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

What is pd in import pandas as pd?

A

an alias

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

Read in a DataFram file into pandas given

import pandas as pd

A

pd.DataFrame.from_dict(‘my_file.???)

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

What is the syntax to export DataFrame to other formats?

A

df.to_csv(‘my_file.csv’)
df.to_excel(‘my_file.xslx’)
df.to_json(‘my_file.json’)
df.to_dict(‘my_file.???’)

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

True or False

like MS Excel, Pandas handles spreedsheet like data called a DataFrame

A

True

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

.txt stands for?

A

tab separated file, known as a text file.

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

.csv stands for?

A

comma separated file, known as a spreadsheet

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

.xlsx stands for?

A

Microsoft Excel Open XML Spreadsheet

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

.json stands for?

A

JavaScript Object Notation

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

What is a delimiter in Pandas?

A

Commas is excel type files are delimiters they separate the data, in Pandas you can detrimine what is going to be used to separate the data being loaded in such as ‘\t’ in .txt files

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

Write the code to read in headers

A

df.columns( )
print(df.columns)

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

Code to read in a specific column

A

df. ([‘Name’])
df. Name

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

Code to read in a specific column limited rows

A

df.Name[0:5]

name column rows 0 - 4

17
Q

Code to read in a number of columns

A

df[[‘Name’, ‘Attack’, ‘Defense’]]

as a list of col names

18
Q

iloc stands for?

A

integer location

19
Q

Code to read in a specific DataFrame row

A

df.iloc[17]

20
Q

Code to read in a multiple DataFrame rows

A

df.iloc[2:10]

rows 2 - 9

21
Q

What will this return in a Pandas DataFrame?

df.iloc[2,1]

A

df.iloc[row, col]

22
Q

What does this code achieve?

for index, row in df.iterrows():
print(index, row[‘Name’])

A

traverses through all the DataFrame rows based on the Name col

23
Q

loc stands for?

A

is a labeled based location

good for using conditional statements

24
Q

What does this code return in a Pandas DataFrame?

df.loc[df[‘Type 1’] == ‘Fire’]

A

returns only those records whose Type 1 attribute is labeled Fire

25
What does this code return in a Pandas DataFrame? df.loc[df['Defense'] \< 25]
returns only the records where the Defense is less than 25
26
What does this code provide? df.describe()
high-level numerical stats on the DataFrame
27
This code will return what? df.sort\_values('Name')
sorted DataFrame by Name col in descending order
28
How would you make this sort descending order instead of the default ascending? df.sort\_values('Name')
df.sort\_values('Name', ascending = False)
29
What does this code return in a Pandas DataFrame? df.sort\_values(['Type 1', 'HP'])
both columns are sorted by alpha and numeric ascending order
30
What does this code return in a Pandas DataFrame? df.sort\_values(['Type 1', 'HP'], ascending=[0, 1])
ascending is set to False, True based on the two cols 'Type 1' and 'HP'
31
What is this code doing? df['New Column'] = df['HP'] + df['Attack'] + df['Defense'] + df['Speed']
adding a New Column to the df with concatenated values from the cols HP, Attack, Defense, and Speed.
32
df.head( ) returns what?
First 5 rows of the DataFrame
33
df.tail( ) returns what?
Last 5 rows of a DataFram
34
df.colums( ) returns what?
All the cols in the DataFrame
35
This code is performing what action? df = df.drop(columns=['New Column'])
dropping the New Column and setting it to the df
36
Given this code how many rows will be returned? df.iloc[:,]
all them df.iloc[rows : , cols :]