ValueError Traceback (most recent call last)
Cell In[1], line 15
4 breakfast_recipes = {
5 “星期一”: [“牛奶”, “鸡蛋”, “全麦面包”],
6 “星期二”: [“酸奶”, “燕麦粥”, “坚果”],
(…)
11 “星期日”: [“豆腐”, “豆浆”, “全麦面包”]
12 }
14 # 创建DataFrame
—> 15 breakfast_df = pd.DataFrame(breakfast_recipes, index=[“早餐食谱”])
17 breakfast_df
File /usr/local/lib/python3.10/site-packages/pandas/core/frame.py:778, in DataFrame.init(self, data, index, columns, dtype, copy)
772 mgr = self._init_mgr(
773 data, axes={“index”: index, “columns”: columns}, dtype=dtype, copy=copy
774 )
776 elif isinstance(data, dict):
777 # GH#38939 de facto copy defaults to False only in non-dict cases
–> 778 mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager)
779 elif isinstance(data, ma.MaskedArray):
780 from numpy.ma import mrecords
File /usr/local/lib/python3.10/site-packages/pandas/core/internals/construction.py:503, in dict_to_mgr(data, index, columns, dtype, typ, copy)
499 else:
500 # dtype check to exclude e.g. range objects, scalars
501 arrays = [x.copy() if hasattr(x, “dtype”) else x for x in arrays]
–> 503 return arrays_to_mgr(arrays, columns, index, dtype=dtype, typ=typ, consolidate=copy)
File /usr/local/lib/python3.10/site-packages/pandas/core/internals/construction.py:119, in arrays_to_mgr(arrays, columns, index, dtype, verify_integrity, typ, consolidate)
116 index = ensure_index(index)
118 # don’t force copy because getting jammed in an ndarray anyway
–> 119 arrays, refs = _homogenize(arrays, index, dtype)
120 # _homogenize ensures
121 # - all(len(x) == len(index) for x in arrays)
122 # - all(x.ndim == 1 for x in arrays)
(…)
125
126 else:
127 index = ensure_index(index)
File /usr/local/lib/python3.10/site-packages/pandas/core/internals/construction.py:630, in _homogenize(data, index, dtype)
627 val = lib.fast_multiget(val, oindex._values, default=np.nan)
629 val = sanitize_array(val, index, dtype=dtype, copy=False)
–> 630 com.require_length_match(val, index)
631 refs.append(None)
633 homogenized.append(val)
File /usr/local/lib/python3.10/site-packages/pandas/core/common.py:573, in require_length_match(data, index)
569 “”"
570 Check the length of data matches the length of the index.
571 “”"
572 if len(data) != len(index):
–> 573 raise ValueError(
574 “Length of values "
575 f”({len(data)}) "
576 “does not match length of index "
577 f”({len(index)})"
578 )
ValueError: Length of values (3) does not match length of index (1)