mholt / PapaParse

Fast and powerful CSV (delimited text) parser that gracefully handles large files and malformed input
http://PapaParse.com
MIT License
12.3k stars 1.14k forks source link

nrows / skiprows #1030

Open scls19fr opened 8 months ago

scls19fr commented 8 months ago

Hello,

I'd like to build a pure JS Dashboard (ie without using tools such as Python Dash)

I have a file like https://raw.githubusercontent.com/scls19fr/krp_python_telemetry/main/Logdata%20Essay%20mini60%202023-10-31.csv

I'm considering using Danfo which uses PapaParse options for reading this CSV file.

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

but I don't see nrows / skiprows options with PapaParse.

Is it something you could consider ?

Or do you think that a workaround should be considered instead?

Kind regards

damieng57 commented 6 months ago

You have this option: skipFirstNLines

However, If you use Typescript, there is a typing issue. You must add this line in index.d.ts for interface ParseConfig or simply ignore the raised error

/**