Skip to content

QST:Getting Error: "ValueError: If using all scalar values, you must pass an index" when converting ndarray to pandas Dataframe #40174

@balandongiv

Description

@balandongiv

When transforming multiple ndarray to a df as per the code below

import  numpy as np
import pandas as pd

ls_a = ['TA', 'BAT', 'T']
xxx = ['xx', 'cc']

feature_no = len(ls_a)
windows_no = len(xxx)


sub_iti = np.repeat([['s1']], (feature_no * windows_no), axis=0).reshape(-1, 1)
tw = np.repeat([xxx], feature_no, axis=1).reshape(-1, 1)
col_iti = np.repeat([ls_a], windows_no, axis=0).reshape(-1, 1)

df=pd.DataFrame ({'sub_iti': sub_iti,'tw': tw,'col_iti': col_iti})

, the compiler return an error

ValueError: If using all scalar values, you must pass an index

Based on OP, the argument index was inputed as below

 df=pd.DataFrame (
             {'sub_iti': sub_iti,
              'tw': tw,
              'col_iti': col_iti},index=range(0,3*2) )

However, the compiler return diff rent error

Exception: Data must be 1-dimensional

May I know how to address this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs TriageIssue that has not been reviewed by a pandas team memberUsage Question

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions