Boa tarde Pessoal,
No meu codigo esta dando um erro que não consigo identificar. Poderiam me ajudar, por favor?
Segue meu codigo abaixo:
import pandas as pd
data = [['1, 2, 3'], ['4, 5, 6'], ['7, 8, 9']]
data
list('321')
df = pd.DataFrame(data, list('321'), list('ZYX'))
df
Tentei tanto no Jupyter como no Colab e nos dois deu o mesmo erro
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
~\anaconda3\lib\site-packages\pandas\core\internals\construction.py in _list_to_arrays(data, columns, coerce_float, dtype)
495 try:
--> 496 result = _convert_object_array(
497 content, columns, dtype=dtype, coerce_float=coerce_float
~\anaconda3\lib\site-packages\pandas\core\internals\construction.py in _convert_object_array(content, columns, coerce_float, dtype)
579 # caller's responsibility to check for this...
--> 580 raise AssertionError(
581 f"{len(columns)} columns passed, passed data had "
AssertionError: 3 columns passed, passed data had 1 columns
The above exception was the direct cause of the following exception:
ValueError Traceback (most recent call last)
<ipython-input-23-39ed356571dd> in <module>
----> 1 df = pd.DataFrame(data, list('321'), list('ZYX'))
2 df
~\anaconda3\lib\site-packages\pandas\core\frame.py in __init__(self, data, index, columns, dtype, copy)
472 if is_named_tuple(data[0]) and columns is None:
473 columns = data[0]._fields
--> 474 arrays, columns = to_arrays(data, columns, dtype=dtype)
475 columns = ensure_index(columns)
476
~\anaconda3\lib\site-packages\pandas\core\internals\construction.py in to_arrays(data, columns, coerce_float, dtype)
459 return [], [] # columns if columns is not None else []
460 if isinstance(data[0], (list, tuple)):
--> 461 return _list_to_arrays(data, columns, coerce_float=coerce_float, dtype=dtype)
462 elif isinstance(data[0], abc.Mapping):
463 return _list_of_dict_to_arrays(
~\anaconda3\lib\site-packages\pandas\core\internals\construction.py in _list_to_arrays(data, columns, coerce_float, dtype)
498 )
499 except AssertionError as e:
--> 500 raise ValueError(e) from e
501 return result
502
ValueError: 3 columns passed, passed data had 1 columns