[Python] Pandasで行数と列数を取得する方法

Python
スポンサーリンク

こんにちはーー

PythonのPandasで行数と列数を取得するコードを作成したので記事にしました。

この記事が誰かの役に立てば幸いです。

ちなみに、動画も作成しています。

スポンサーリンク

概要

↓の行数21,列数1のcsvを読み込んで実行します。

did Prophet find anyways to put his 944 billion-dollar cash pile to work over the past
big Acquisitions and he didn’t come up with any of the second quarter
play some cash it was just six tilian which has been the lowest amount he’s repurchased over the past years though
please find ways to really supercharged Brookshire’s growth I mean BuyBacks or acquisition all our kind of struggling just a little bit
this is them selves how are they faring Berkshire actually a good amount of resilience
obviously the second quarter of last year be pretty rough businesses like the railroad
some of that was you know busier traffic on the rails but also combined with some productivity efforts they made over the past year when they were facing lower volume
seem to be faring quite well we continue to see supply chain issues really affecting inflationary pressures any sign of how that’s affecting their big
the Warren actually warned about this back in May at his annual meeting he said you know we’re already starting to see price
do kind of affect the supply chain and they were having to raise some prices at their own businesses he caught the red-hot economy already and we saw that continuing into the second quarter
particularly some of their Building Products companies the ones that handle you know different products for housing ended up having to you no pay or higher cost for stuff like lovebirds

コード

import pandas as pd # pandasを使います
path = "./test.csv" # 読み込むcsvファイルのパスを定義
data = pd.read_csv(path) # csvを読み込みます

print("行数と列数を表示:",data.shape)
print("行数を表示:",len(data))
print("列数を表示:",len(data.columns))

これだけです。

実行結果

行数と列数を表示: (21, 1)
行数を表示: 21
列数を表示: 1

コメント

タイトルとURLをコピーしました