DataFrames - PANDAS DataFrames Flashcards
A Pandas DataFrame is a 2 dimensional data structure, like a 2 dimensional array, or a table with rows and columns.
Pandas DataFrames
Locate Row - DataFrame is like a table with rows and columns.
Locate Row
Locate Row - Pandas use the loc attribute to return one or more specified row(s)
Locate Row
DataFrame - When using [], the result is a Pandas DataFrame.
DataFrame
Named Indexes - With the index argument, you can name your own indexes.
Named Indexes
Locate Named Indexes - Use the named index in the loc attribute to return the specified row(s).
Locate Named Indexes
Load Files Into a DataFrame -
If your data sets are stored in a file, Pandas can load them into a DataFrame.
Load Files Into a DataFrame
Exercise - True or False. A DataFrame is like a table with rows and columns.
True
Exercise - Insert the correct Pandas method to create a DataFrame.
pd.DataFrame(data)
Exercise - Insert the correct syntax to return the first row of a DataFrame.
df.loc[0]
Exercise - Insert the correct syntax for loading CSV files into a DataFrame.
df.read_csv(data)
Exercise - Consider the following Code:
data = {
‘calories’: [420, 380, 390],
‘duration’: [50, 40, 45]
}
df = pd.DataFrame(data)
print(df.loc[0]) What type will the printed result have?
A Pandas Series
Exercise - Insert the correct syntax for loading JSON files into a DataFrame.
df.read_json
(data)
Exercise - Insert the correct syntax for loading a Python dictionary called “data” into a DataFrame.
pd.DataFrame(data)
Exercise - Insert the correct syntax for returning the headers and the first 10 rows of a DataFrame.
df.head(10)
Exercise - When using the head() method, how many rows are returned if you do not specify the number?
The headers and 5 rows