目录
pandas.DataFrame.info
0、功能:打印一个DataFrame的简要介绍(index范围、columns的dtype、非空值的数量和内存的使用情况)
1、详解
(1)、函数形式
DataFrame.info(verbose=None, buf=None, max_cols=None, memory_usage=None, show_counts=None)[source]
(2)、参数
- verbose(adj 冗长的): bool, optional
- 决定是否打印完整的摘要
- 如果为False,那么会省略一部分
- buf: writable buffer, defaults to sys.stdout
- 决定将输出发送到哪里
- 默认情况下, 输出打印到sys.stdout
- max_cols: int, optional
- 从“详细输出”转换为“缩减输出”,如果DataFrame的列数超过max_cols,则缩减输出。
- memory_usage: bool, str, optional
- 决定是否应显示DataFrame元素(包括索引)的总内存使用情况
- 默认情况下为True
- True始终显示内存使用情况;False永远不会显示内存使用情况。
- show_counts: bool, optional
- 是否显示非空值的数量
- 值为True始终显示计数,而值为False则不显示计数
2、例子(官方教程)
生成一个dataframe对象
>>> int_values = [1, 2, 3, 4, 5]
>>> text_values = ['alpha', 'beta', 'gamma', 'delta', 'epsilon']
>>> float_values = [0.0, 0.25, 0.5, 0.75, 1.0]
>>> df = pd.DataFrame({"int_col": int_values, "text_col": text_values,
... "float_col": float_values})
>>> df
int_col text_col float_col
0 1 alpha 0.00
1 2 beta 0.25
2 3 gamma 0.50
3 4 delta 0.75
4 5 epsilon 1.00
verbose=True:打印完整信息(index范围、每列的信息、内存使用情况)
>>> df.info(verbose=True)
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5 entries, 0 to 4
Data columns (total 3 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 int_col 5 non-null int64
1 text_col 5 non-null object
2 float_col 5 non-null float64
dtypes: float64(1), int64(1), object(1)
memory usage: 248.0+ bytes
verbose=Flase:省去每列的信息(index范围、column范围和dtype、内存使用情况)
>>> df.info(verbose=False)
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5 entries, 0 to 4
Columns: 3 entries, int_col to float_col
dtypes: float64(1), int64(1), object(1)
memory usage: 248.0+ bytes
参考链接:这个