日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python中info的用法_Python pandas.DataFrame.info函数方法的使用

發布時間:2025/3/11 python 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python中info的用法_Python pandas.DataFrame.info函数方法的使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

DataFrame.info(self, verbose=None, buf=None, max_cols=None, memory_usage=None, null_counts=None) [source]

打印DataFrame的簡要摘要。

此方法顯示有關DataFrame的信息,包括索引dtype和列dtype,非空值和內存使用情況。

參數:verbose : bool,可選

是否打印完整的摘要。默認情況下,

pandas.options.display.max_info_columns

遵循中的設置 。

buf : 可寫緩沖區,默認為sys.stdout

將輸出發送到哪里。默認情況下,

輸出將打印到sys.stdout。如果需要進一步處理輸出,

請傳遞可寫緩沖區。

max_cols : int,可選

何時從詳細輸出切換到截斷輸出。

如果DataFrame的列數超過max_cols列,

則使用截斷的輸出。默認情況下,

使用中的設置 pandas.options.display.max_info_columns。

memory_usage : bool,str,可選

指定是否應顯示DataFrame元素(包括索引)

的總內存使用情況。默認情況下,

這遵循pandas.options.display.memory_usage設置。

True始終顯示內存使用情況。

False永遠不會顯示內存使用情況。

‘deep’ 的值等效于“真正的內省”。

內存使用情況以可讀單位(以2為基數的表示形式)

顯示。無需深入自省,

就可以根據列dtype和行數進行內存估計,

假設值為相應的dtype消耗相同的內存量。

使用深度內存自省,

將以計算資源為代價執行實際內存使用量計算。

null_counts : 布爾值,可選

是否顯示非空計數。默認情況下,

僅當框架小于 pandas.options.display.max_info_rows

和時顯示 pandas.options.display.max_info_columns。

值為True始終顯示計數,而值為False則不顯示計數。

返回值:None

此方法打印DataFrame的摘要并返回None。

例子>>> 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

打印所有列的信息:>>> df.info(verbose=True)

RangeIndex: 5 entries, 0 to 4

Data columns (total 3 columns):

int_col 5 non-null int64

text_col 5 non-null object

float_col 5 non-null float64

dtypes: float64(1), int64(1), object(1)

memory usage: 248.0+ bytes

顯示列數及其dtype的摘要,但不顯示每列的信息:>>> df.info(verbose=False)

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

將DataFrame.info的輸出通過管道傳遞到緩沖區而不是sys.stdout,獲取緩沖區內容并寫入文本文件:>>> import io

>>> buffer = io.StringIO()

>>> df.info(buf=buffer)

>>> s = buffer.getvalue()

>>> with open("df_info.txt", "w",

... encoding="utf-8") as f: # doctest: +SKIP

... f.write(s)

260

該memory_usage參數允許深刻反省模式,為大DataFrames和微調內存優化特別有用:>>> random_strings_array = np.random.choice(['a', 'b', 'c'], 10 ** 6)

>>> df = pd.DataFrame({

... 'column_1': np.random.choice(['a', 'b', 'c'], 10 ** 6),

... 'column_2': np.random.choice(['a', 'b', 'c'], 10 ** 6),

... 'column_3': np.random.choice(['a', 'b', 'c'], 10 ** 6)

... })

>>> df.info()

RangeIndex: 1000000 entries, 0 to 999999

Data columns (total 3 columns):

column_1 1000000 non-null object

column_2 1000000 non-null object

column_3 1000000 non-null object

dtypes: object(3)

memory usage: 22.9+ MB>>> df.info(memory_usage='deep')

RangeIndex: 1000000 entries, 0 to 999999

Data columns (total 3 columns):

column_1 1000000 non-null object

column_2 1000000 non-null object

column_3 1000000 non-null object

dtypes: object(3)

memory usage: 188.8 MB

總結

以上是生活随笔為你收集整理的python中info的用法_Python pandas.DataFrame.info函数方法的使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。