Pandas_JAS Flashcards
How to refer to a single column in a DF
DFname[‘columnname’].head() ##head() by default gives first 5 rows
Technically, a single column is a ______ not a ______
Series; DataFrame
A Series is part of a DataFrame
After typing code into the ______, highlight the code of interest and hit ____ to sent it to the ________
Editor
F9
REPL (console)
Normally you to install third party libraries with a tool like _____, but if you’re using ________ it comes with Pandas installed
pip
Anaconda Python Bundle
When importing Pandas the convention is to name it ______
pd.
To load a csv file:
DFname = pd._______(_______,(DATA_DIR, ‘filename.csv’))
read_csv
path.join
DATA_DIR is a variable where you have given the path to your file, e.g., DATA_DIR = ‘/Users/UserName/PythonDirectory’
What result does this give:
type(DFname)
pandas.core.frame.DataFrame
what method is called to give (by default) the first 5 rows of a DataFrame?
head()
DFname.head()
head() is a method because you can pass it the number of rows to print, ________ are used without passing any data in parenthesis
attributes
the attribute _______ returns the names of each column in the DF
columns
the attribute ______ returns the number of rows and columns in the DF
shape
______ will turn any Series into a one-column DF
to_frame()
DFname.[‘columnname’].to_frame().head()
to refer to multiple columns in a DF, you pass it a ______, and the result is _______
list
a DataFrame
DFname[[‘col1’, ‘col2’, ‘col3’]].head()
when working with multiple columns you must use double brackets
An index is a built in column of ________. If you don’t designate a column as a specific index, the default is a ________.
row IDs
series of numbers starting at zero
Indexes can be _______
Any type of data (strings, dates, etc)
How to assign an index to a DF?
DFname.set_index(‘columnname’)
This creates a copy of the DF with this index.
What must be passed to set_index() to create the index on the original DF?
Inplace = True
DFname.set_index(‘columnname’, inplace=True)
Or overwrite DFname
DFname = DFname.set_index(‘columnname’)
Most DataFrame methods return copies unless ________ is explicity included
Inplace = True
The opposite of set_index() is ______
Reset_index()
How to sort a DF?
DFname.sort_value(‘columnname’, ascending = False, inplace = True)