Pandas Flashcards
Write the code that is required to run pandas
import pandas as pd
Read in a csv file into pandas given
import pandas as pd
pd.read_csv(‘myfile.csv’)
Read in a excel file into pandas given
import pandas as pd
pd.read_excel(‘my_file.xlsx’)
Read in a json file into pandas given
import pandas as pd
pd.read_json(‘my_file.json’)
What is pd in import pandas as pd?
an alias
Read in a DataFram file into pandas given
import pandas as pd
pd.DataFrame.from_dict(‘my_file.???)
What is the syntax to export DataFrame to other formats?
df.to_csv(‘my_file.csv’)
df.to_excel(‘my_file.xslx’)
df.to_json(‘my_file.json’)
df.to_dict(‘my_file.???’)
True or False
like MS Excel, Pandas handles spreedsheet like data called a DataFrame
True
.txt stands for?
tab separated file, known as a text file.
.csv stands for?
comma separated file, known as a spreadsheet
.xlsx stands for?
Microsoft Excel Open XML Spreadsheet
.json stands for?
JavaScript Object Notation
What is a delimiter in Pandas?
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
Write the code to read in headers
df.columns( )
print(df.columns)
Code to read in a specific column
df. ([‘Name’])
df. Name
Code to read in a specific column limited rows
df.Name[0:5]
name column rows 0 - 4
Code to read in a number of columns
df[[‘Name’, ‘Attack’, ‘Defense’]]
as a list of col names
iloc stands for?
integer location
Code to read in a specific DataFrame row
df.iloc[17]

Code to read in a multiple DataFrame rows
df.iloc[2:10]

rows 2 - 9
What will this return in a Pandas DataFrame?
df.iloc[2,1]
df.iloc[row, col]
What does this code achieve?
for index, row in df.iterrows():
print(index, row[‘Name’])
traverses through all the DataFrame rows based on the Name col

loc stands for?
is a labeled based location
good for using conditional statements
What does this code return in a Pandas DataFrame?
df.loc[df[‘Type 1’] == ‘Fire’]
returns only those records whose Type 1 attribute is labeled Fire