Editing DataFrame
Table of contents
import pandas as pd
Append/Change Values
closely related to indexing/selecting
dataframe.loc['row_name'] = data # single row
dataframe.loc[['row_name_1', 'row_name_2', ... ]] = data # multiple rows (change only)
dataframe.loc[['row_name_1st' : 'row_name_last']] = data # multiple rows (change only)
dataframe.loc[boolean_mask] = data # conditional rows (change only)
dataframe['column_name'] = data # single column
dataframe[['column_name_1, column_name_2, ... ']] = data # multiple columns
dataframe.loc['row_name', 'column_name'] = data # single entry
dataframe.iloc[[1, 3], [1, 4]] = data # multiple entries (change only) (1, 1) (1, 4) (3, 1) (3, 4)
Delete
dataframe.drop(label, axis, | index, columns, inplace) # row/column 제거
- labels, index, columns : single label or list-like
labels, axis=0
is equivalent toindex=labels
.labels, axis=1
is equivalent tocolumns=labels
.
- axis : {0 or ‘index’, 1 or ‘columns’}
Data type
dtypes
DataFrame.dtypes # return : pandas.Series of data_type
Series.dtype
Index.dtype
astype()
DataFrame.astype(dtype)
Series.astype(dtype)
Index.astype(dtype)
- dtype : data type(str), or dict of column name -> data type