Home > Back-end >  Shape of passed values is (12, 1), indices imply (1, 12)
Shape of passed values is (12, 1), indices imply (1, 12)

Time:07-09

I tried to create a table.

p_data = ["20", "30", "40", "50", "60", "70", "80", "90",
          "100", "110", "120", "130"];
p_columns = ["2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017",
             "2018", "2019", "2020", "2021"]

data_frame = pd.DataFrame(columns=p_columns , index=["house"], data=p_data )

I got an error: Shape of passed values is (12, 1), indices imply (1, 12)

I want my table looks like this: image of what i want

Someone can help me please?

CodePudding user response:

You need to use [data] as the input must be 2D if you specify the index/columns:

data_frame = pd.DataFrame(columns=p_data, index="house", data=[p_data])

output:

       20  30  40  50  60  70  80  90  100  110  120  130
house  20  30  40  50  60  70  80  90  100  110  120  130

Also I imagine you rather want p_columns as columns:

data_frame = pd.DataFrame(columns=p_columns, index="house", data=[p_data])

output:

      2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021
house   20   30   40   50   60   70   80   90  100  110  120  130
  • Related