iloc, loc
set_index()
isnull(), notnull()
data.attribute
으로 data에 속해있는 속성 호출 가능data['attribut']
으로도 호출 가능[행, 열]
로 호출:
은 '모든 행/열'을 의미iloc
는 0부터 시작해서 자기자신을 포함하지 않지만 loc
는 0부터 시작해서 자기자신을 포함0:10
은 iloc
에서는 0,...,9를 loc
에서는 0,...,10를 의미data.set_index('name')
으로 새로운 인덱스(name)을 생성data.loc[data.column name == 'value']
으로 column에서 value와 일치하는 데이터만 가져올 수 있음data.['column name'] = 'value'
로 columns name에 value 할당 가능Select the description column from reviews and assign the result to the variable desc
desc = reviews['description']
Select the first value from the description column of reviews, assigning it to variable first_description
first_description = reviews['description'][0]
Select the first row of data (the first record) from reviews, assigning it to the variable first_row
first_row = reviews.iloc[0]
Select the first 10 values from the description column in reviews, assigning the result to variable first_descriptions.
first_descriptions = reviews.description.iloc[0:10]
Select the records with index labels 1, 2, 3, 5, and 8, assigning the result to the variable sample_reviews
sample_reviews = reviews.iloc[[1,2,3,5,8],]
Create a variable df containing the country, province, region_1, and region_2 columns of the records with the index labels 0, 1, 10, and 100
df = reviews.loc[[0,1,10,100], ['country', 'province', 'region_1', 'region_2']]
Create a variable df containing the country and variety columns of the first 100 records.
df = reviews.loc[:99, ['country', 'variety']]
Create a DataFrame italian_wines containing reviews of wines made in Italy
italian_wines = reviews.loc[reviews.country =='Italy',]
Create a DataFrame top_oceania_wines containing all reviews with at least 95 points (out of 100) for wines from Australia or New Zealand.
top_oceania_wines = reviews.loc[reviews.country.isin(['Australia', 'New Zealand']) & (reviews.points >= 95),]