Open chinobing opened 3 years ago
ValueError Traceback (most recent call last)
/var/folders/5z/nfxgl_ps6qlf5tvrct964q980000gn/T/ipykernel_25037/2953129566.py in
~/Library/Python/3.7/lib/python/site-packages/pandas/core/frame.py in from_dict(cls, data, orient, dtype, columns) 1307 raise ValueError("only recognize index or columns for orient") 1308 -> 1309 return cls(data, index=index, columns=columns, dtype=dtype) 1310 1311 def to_numpy(
~/Library/Python/3.7/lib/python/site-packages/pandas/core/frame.py in init(self, data, index, columns, dtype, copy) 466 467 elif isinstance(data, dict): --> 468 mgr = init_dict(data, index, columns, dtype=dtype) 469 elif isinstance(data, ma.MaskedArray): 470 import numpy.ma.mrecords as mrecords
~/Library/Python/3.7/lib/python/site-packages/pandas/core/internals/construction.py in init_dict(data, index, columns, dtype) 281 arr if not is_datetime64tz_dtype(arr) else arr.copy() for arr in arrays 282 ] --> 283 return arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype) 284 285
~/Library/Python/3.7/lib/python/site-packages/pandas/core/internals/construction.py in arrays_to_mgr(arrays, arr_names, index, columns, dtype, verify_integrity) 76 # figure out the index, if necessary 77 if index is None: ---> 78 index = extract_index(arrays) 79 else: 80 index = ensure_index(index)
~/Library/Python/3.7/lib/python/site-packages/pandas/core/internals/construction.py in extract_index(data) 395 lengths = list(set(raw_lengths)) 396 if len(lengths) > 1: --> 397 raise ValueError("arrays must all be same length") 398 399 if have_dicts:
ValueError: arrays must all be same length
@AwesomeCap in the third code block, modify the 5th code line as:
_df = pd.DataFrame.from_dict(outputdict, orient='index').T.apply(pd.to_numeric)
Sample Code
output
Credits: