What is right way of debugging error in jupyter


I use a csv file for practises

when i execute pd.DataFrame(df1)

then output come

but when i execute pd.Series(df1)

then error come

from this error i just understand that some error near line number 6931

ValueError                                Traceback (most recent call last)
c:\users\regan sharma\appdata\local\programs\python\python36-32\lib\site-packages\pandas\core\common.py in _asarray_tuplesafe(values, dtype)
    398                 result = np.empty(len(values), dtype=object)
--> 399                 result[:] = values
    400             except ValueError:

ValueError: could not broadcast input array from shape (6931,17) into shape (6931)

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-14-54221e6a872b> in <module>()
----> 1 pd.Series(df1)

c:\users\regan sharma\appdata\local\programs\python\python36-32\lib\site-packages\pandas\core\series.py in __init__(self, data, index, dtype, name, copy, fastpath)
    262             else:
    263                 data = _sanitize_array(data, index, dtype, copy,
--> 264                                        raise_cast_failure=True)
    266                 data = SingleBlockManager(data, index, fastpath=True)

c:\users\regan sharma\appdata\local\programs\python\python36-32\lib\site-packages\pandas\core\series.py in _sanitize_array(data, index, dtype, copy, raise_cast_failure)
   3275             raise Exception('Data must be 1-dimensional')
   3276         else:
-> 3277             subarr = _asarray_tuplesafe(data, dtype=dtype)
   3279     # This is to prevent mixed-type Series getting all casted to

c:\users\regan sharma\appdata\local\programs\python\python36-32\lib\site-packages\pandas\core\common.py in _asarray_tuplesafe(values, dtype)
    400             except ValueError:
    401                 # we have a list-of-list
--> 402                 result[:] = [tuple(x) for x in values]
    404     return result

ValueError: cannot copy sequence with size 17 to array axis with dimension 6931

1 Answer(s)


Try this one:

import pandas as pd
from pandas import Series, DataFrame,read_csv
df = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data', header=None)

df1 = pd.DataFrame(df)

series = df.iloc[0:] #slicing the dataframe here


series = read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data',header=0) #loading here as series object


Your Answer

Click on this code-snippet-icon icon to add code snippet.

Upload Files (Maximum image file size - 1.5 MB, other file size - 10 MB, total size - not more than 50 MB)