全日本シクロクロスエリートのラップタイムデータを集計してみました。 pic.twitter.com/lfxSh9mICz
— ストライピーなザイコー (@Zaikou) 2019年12月17日
http://wakitasoft.com/Timing/Results/2019/20191208/lap_Result01.pdf
TSV
import pandas as pd import japanize_matplotlib import matplotlib.pyplot as plt import matplotlib.ticker as ticker df = pd.read_csv("uchiko2019.tsv", sep="\t") df df1 = df.iloc[:, [2, 28, 29, 30, 31, 32, 33, 34, 35, 36]].copy() df1.columns = [ "名前", "LAP1", "LAP2", "LAP3", "LAP4", "LAP5", "LAP6", "LAP7", "LAP8", "LAP9", ] df1.set_index("名前", inplace=True) # 欠損値の場合は前の順位で補完 df1.fillna(method="ffill", axis=1, inplace=True) df1 ax = df1.T.plot( figsize=(15, 20), xlim=(-0.5, 8.5), ylim=(70, 0), marker="o", ms=5, legend=False ) # Y軸のラベルに名前を表示 ax.set_yticklabels(["", *df1.index, ""]) # Y軸のラベルを右側に変更 ax.yaxis.tick_right() ax.set_yticks(list(range(70))) plt.show() # トップとのタイム差 df2 = df.iloc[:, [2, 10, 11, 12, 13, 14, 15, 16, 17, 18]].copy() df2.set_index("名前", inplace=True) df2 # 文字列のフォーマットをH:M:S形式に揃える df3 = df2.applymap( lambda d: ":".join(("0:" + d).split(":")[-3:]) if pd.notna(d) else "" ) # 文字列をTimeDelta型に変換 df3 = df3.apply(pd.to_timedelta) df3.head(10) df3.dtypes # トップとのタイム差計算 df3_diff = df3.apply(lambda x: x - x.min()) df3_diff # グラフ表示 ax = df3_diff.T.plot(figsize=(25, 20), grid=True) @ticker.FuncFormatter def yfmt(y, pos): m = int(y // (1000000000 * 60)) s = int((y // 1000000000) - (m * 60)) return f"{m:02d}:{s:02d}" # Y軸の目盛を0:30ごと ax.yaxis.set_major_locator(ticker.MultipleLocator(1000000000 * 30)) # Y軸の目盛のフォーマット ax.yaxis.set_major_formatter(yfmt) # 0からスタート ax.set_ylim(bottom=0) # Y軸反転 ax.invert_yaxis() plt.legend(bbox_to_anchor=(1.05, 1), loc="upper left", borderaxespad=0, fontsize=10) plt.show()