ファイル入・出力

original=pd.read_excel("./history/allIPCList.xlsx",header=0,index_col=0)
with open('./pickle/{}{}.pickle'.format(x,y), 'wb') as wb:
    pickle.dump(df , wb)
df.to_excel('history/LogAllIPCList.xlsx', sheet_name='new_sheet_name')

データフレーム作成

df_sample =\
pd.DataFrame([["day1","day2","day1","day2","day1","day2"],
              ["A","B","A","B","C","C"],
              [100,150,200,150,100,50],
              [120,160,100,180,110,80]] ).T  #とりあえず適当なデータを作ります

df_sample.columns = ["day_no","class","score1","score2"]  #カラム名を付ける
df_sample.index   = [11,12,13,14,15,16] 

構造確認

# 行数の確認
len(df_sample)

# 次元数の確認
df_sample.shape #(行数、列数)の形で返す

# カラム情報の一覧
df_sample.info() #カラム名とその型の一覧

# 各列の基礎統計量の確認
# Rでいうところのsummary()
df_sample.describe() # 平均、分散、4分位など

# head / tail
df_sample.head(10) #先頭10行を確認
df_sample.tail(10) #先頭10行を確認

日付処理

import datetime
dt_now = datetime.datetime.now()
print(dt_now)
#日付変換
dt = datetime.datetime(2018, 2, 1, 12, 15, 30, 2000)
d = datetime.date(2018, 2, 1)


print(pd.to_datetime(df['B'], format='%Y年%m月%d日 %H時%M分'))


#うるう年表示
import calendar
print(calendar.monthrange(2019, 1))
# (1, 31)
print(calendar.monthrange(2019, 1)[1])
# 31

型の変更

pd.to_datetime(df['A'])