0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Pandas操作

Last updated at Posted at 2023-08-22

Pandasメソッド

①Pandas、データの読み込みと確認
②データの抽出
③データの変換
④データの欠損
⑤値や欠損値の削除や置換

①Pandas、データの読み込みと確認

#Pandasの読み込み
import pandas as pd
#データの読み込み
df = pd.read_csv('読み込むデータ.csv')
#先頭5行を表示
df.head()

②データの抽出

#10行とColumn_nameの取得
df.loc[10,'Column_name']
#10行3列を表示
df.iloc[10,3]
#条件を指定して抽出1  (10より小さいものを抽出)
df[df['Column_name'] < 10]
#条件を指定して抽出1  (70から80の間を抽出)
df.query('70 <= Column_name <= 80')
#重複の削除
df.drop_duplicates()
#データの量の確認
df.shape

③データの変換

#列をindexにする
df.set_index('Column_name', inplace=True)
#Columnの名前を変更
df.rename(columns={'Column_name':'NewColumn_name'})
Column列を降順にする
df.sort_values(by='Column_name', ascending=False)

④データの欠損確認

#データの欠損値の状態確認
df.isnull().sum()

⑤値や欠損値の削除や置換

#Column_nameにある欠損値を平均値で置換
df['Column_name'].fillna(df['Column_name'].mean(), inplace=True)
#欠損値がある行を削除
df.dropna(subset=['Column_name'], inplace=True)
#列ごと削除
df.drop('Column_name', axis=1)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?