Pandas Flashcards
1
Q
loc
A
loc is primarily label based; when two arguments are used, you use column headers and row indexes to select the data you want. loc can also take an integer as a row or column number.
df.loc[0,’Artist’]: ‘Michael Jackson’
2
Q
iloc
A
iloc is integer-based. You use column numbers and row numbers to get rows or columns at particular positions in the data frame.
3
Q
iloc slicing
A
z=df.iloc[0:2,0:3]
4
Q
Import pandas
A
Pandas have a list of functions including: read_csv() Series() DataFrame values
import pandas as pd
csv_path = “a.csv”
df = pd.read_csv(csv_path)
df.head() examines the frist 5 rows of data frame.
5
Q
create new dataframe consisting of one column
A
x=df[[‘Length’]]
6
Q
create multiple columns
A
y=df[[‘Artist’, ‘Length’, ‘Genre’]]