Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nrows / skiprows #1030

Open
scls19fr opened this issue Nov 13, 2023 · 1 comment
Open

nrows / skiprows #1030

scls19fr opened this issue Nov 13, 2023 · 1 comment

Comments

@scls19fr
Copy link

scls19fr commented Nov 13, 2023

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
Copy link

damieng57 commented Jan 17, 2024

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

/**

  • Skip N lines bedore processing file
  • @default // auto-detect
    */
    skipFirstNLines?: number | undefined;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants