サーチ…


DataFrame情報とメモリ使用量を取得する

列名とデータ型を含むDataFrameに関する基本情報を取得するには:

import pandas as pd

df = pd.DataFrame({'integers': [1, 2, 3], 
                   'floats': [1.5, 2.5, 3], 
                   'text': ['a', 'b', 'c'], 
                   'ints with None': [1, None, 3]})

df.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 3 entries, 0 to 2
Data columns (total 4 columns):
floats            3 non-null float64
integers          3 non-null int64
ints with None    2 non-null float64
text              3 non-null object
dtypes: float64(2), int64(1), object(1)
memory usage: 120.0+ bytes

DataFrameのメモリ使用量を取得するには:

>>> df.info(memory_usage='deep')
<class 'pandas.core.frame.DataFrame'>
Int64Index: 3 entries, 0 to 2
Data columns (total 4 columns):
floats            3 non-null float64
integers          3 non-null int64
ints with None    2 non-null float64
text              3 non-null object
dtypes: float64(2), int64(1), object(1)
memory usage: 234.0 bytes

DataFrameの列名を一覧表示する

df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]})

DataFrameの列名を一覧表示するには:

>>> list(df)
['a', 'b', 'c']

このリストの理解方法は、デバッガを使用する場合に特に便利です。

>>> [c for c in df]
['a', 'b', 'c']

これは長い道のりです:

sampledf.columns.tolist()

リストの代わりにインデックスとして印刷することもできます(ただし、多くの列を持つデータフレームではあまり表示されません)。

df.columns

Dataframeのさまざまな要約統計情報

import pandas as pd
df = pd.DataFrame(np.random.randn(5, 5), columns=list('ABCDE'))

さまざまな要約統計を生成する。数値の場合、非NA /ヌル値( count )、平均( mean )、標準偏差stdおよび5桁の要約として知られる値:

  • min :最小(最小観測)
  • 25% :低四分位または四分位(Q1)
  • 50% :中央値(中間値、Q2)
  • 75% :上位四分位または三分位(Q3)
  • max :最大値(最大値)
>>> df.describe()
              A         B         C         D         E
count  5.000000  5.000000  5.000000  5.000000  5.000000
mean  -0.456917 -0.278666  0.334173  0.863089  0.211153
std    0.925617  1.091155  1.024567  1.238668  1.495219
min   -1.494346 -2.031457 -0.336471 -0.821447 -2.106488
25%   -1.143098 -0.407362 -0.246228 -0.087088 -0.082451
50%   -0.536503 -0.163950 -0.004099  1.509749  0.313918
75%    0.092630  0.381407  0.120137  1.822794  1.060268
max    0.796729  0.828034  2.137527  1.891436  1.870520


Modified text is an extract of the original Stack Overflow Documentation
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow