[Python] Can't get grouped data into numpy array

Discussão em 'Python' iniciado por Stack, Março 9, 2025.

  1. Stack

    Stack Membro Participativo

    I have a CSV file like this:

    Ngày(Date),Số(Number)
    07/03/2025,8
    07/03/2025,9
    ...
    06/03/2025,6
    06/03/2025,10
    06/03/2025,18
    06/03/2025,14
    ...


    (Each day has 27 numbers)

    I want to predict a list of 27 numbers on the next day using LSTM. It keeps getting an error on this step:

    data_matrix = np.array(grouped_data.loc[:, "Số"].tolist())


    with

    KeyError: 'Số'


    (which means 'Number')

    Here is my code:

    import numpy as np
    import pandas as pd

    df = pd.read_csv("C:/Users/Admin/lonum_fixed.csv", encoding="utf-8", sep=",")
    df.columns = df.columns.str.strip()

    grouped_data = df.groupby("Ngày")[["Số"]].apply(lambda x: list(map(int, x["Số"].values))).reset_index()
    grouped_data["Số"] = grouped_data["Số"].apply(lambda x: eval(x) if isinstance(x, str) else x)

    data_matrix = np.array(grouped_data.loc[:, "Số"].tolist())

    Continue reading...

Compartilhe esta Página