Skip to content

Issue with figure 3 notebook #1

@lgatto

Description

@lgatto

Running the following cell

melted = pd.melt(plotdf, id_vars='index', value_vars=plotdf.columns.tolist())
melted.rename({'variable':'category', 'index':'total_peptides', 'value':'num_proteins'}, axis=1, inplace=True)
melted = melted[melted['num_proteins'].notnull()]
melted.head()

I hit this exception

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-31-eaf8af8ae2ed> in <module>
----> 1 melted = pd.melt(plotdf, id_vars='index', value_vars=plotdf.columns.tolist())
      2 melted.rename({'variable':'category', 'index':'total_peptides', 'value':'num_proteins'}, axis=1, inplace=True)
      3 melted = melted[melted['num_proteins'].notnull()]
      4 melted.head()

~/anaconda3/lib/python3.8/site-packages/pandas/core/reshape/melt.py in melt(frame, id_vars, value_vars, var_name, value_name, col_level, ignore_index)
    134         mdata[col] = np.asanyarray(frame.columns._get_level_values(i)).repeat(N)
    135 
--> 136     result = frame._constructor(mdata, columns=mcolumns)
    137 
    138     if not ignore_index:

~/anaconda3/lib/python3.8/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

~/anaconda3/lib/python3.8/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 

~/anaconda3/lib/python3.8/site-packages/pandas/core/internals/construction.py in arrays_to_mgr(arrays, arr_names, index, columns, dtype, verify_integrity)
     81 
     82         # don't force copy because getting jammed in an ndarray anyway
---> 83         arrays = _homogenize(arrays, index, dtype)
     84 
     85         columns = ensure_index(columns)

~/anaconda3/lib/python3.8/site-packages/pandas/core/internals/construction.py in _homogenize(data, index, dtype)
    349                     val = dict(val)
    350                 val = lib.fast_multiget(val, oindex._values, default=np.nan)
--> 351             val = sanitize_array(
    352                 val, index, dtype=dtype, copy=False, raise_cast_failure=False
    353             )

~/anaconda3/lib/python3.8/site-packages/pandas/core/construction.py in sanitize_array(data, index, dtype, copy, raise_cast_failure)
    494     elif subarr.ndim > 1:
    495         if isinstance(data, np.ndarray):
--> 496             raise Exception("Data must be 1-dimensional")
    497         else:
    498             subarr = com.asarray_tuplesafe(data, dtype=dtype)

Exception: Data must be 1-dimensional

Let me know what additional information you need from me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions