Hello,
I’d like to read this file https://raw.githubusercontent.com/scls19fr/krp_python_telemetry/main/Logdata%20Essay%20mini60%202023-10-31.csv (ideally as 2 Danfo.js dataframes)
With Python Pandas I’m doing
def load_krp_file(fname):
nrows = 12
df_head = pd.read_csv(fname, nrows=nrows, names=["key", "value"])
df_head = df_head.set_index("key")
df = pd.read_csv(fname, skiprows=nrows)
units = df.iloc[0, :]
units.name = "units"
cols = df.columns
df = df.drop(0)
for col in df.columns:
df[col] = df[col].astype(float)
df["Lap"] = ((df["Distance"] - df["Distance"].shift()) < 0).astype(int).cumsum()
#df["Laptime"] = pd.NaT
df["Starttime"] = np.where((df["Distance"] - df["Distance"].shift()) < 0, df["Time"], np.NaN)
#df["Starttime"].iloc[0] = 0
df.loc[df.index[0], "Starttime"] = 0
df["Starttime"] = df["Starttime"].ffill()
#df["Starttime"] = df["Starttime"].fillna(method="ffill")
df["Laptime"] = df["Time"] - df["Starttime"]
df["Time"] = pd.to_datetime(df["Time"], unit="s")
#df["Time"] = pd.to_timedelta(df["Time"], unit="s")
#df["Laptime"] = pd.to_datetime(df["Laptime"], unit="s")
df = df.set_index("Time")
laps = df["Lap"].unique()
laptimes = df.groupby("Lap")["Laptime"].last()[0:-1]
return df_head, units.to_frame(), df, laps, laptimes
unfortunately I don’t see a nrows
option to define the number of rows to read, nor a skiprows
option to skip a given number of rows.
What are according your JS experience the best way of reading such a file and to plot in Plotly graphs?
Kind regards