two days ago, I did a short data analysis on a certain dataset. Today, I want to built upon this work on a different project. So I copy-pasted some of the code, while for the project I am starting today the code worked just fine, the project from two days ago is running into following error.
It wouldbe great if someone could explain me what the problem is and how to solve it, because I ran into this before. Back then I solved it by creating a new code-sheet, which should not be the way to go, since I want to run the code several time without always creating a new notebook.
what I am working with:
Jupyter Notebook
Python 3.6 (in a virt env)
Linux 22.04
You find screenshots of both codes and outputs in the following: Input-Output 1 Input-Output 2
Best regards, Solaris
categorical_features = dtype[dtype == 'object'].index
readable_df[numerical_features].describe()
# Split features into categorical and numerical, print numerical
dtype = readable_df.dtypes
numerical_features = dtype[dtype == 'int64'].index
categorical_features = dtype[dtype == 'object'].index
ā
readable_df[numerical_features].describe()
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [7], in <cell line: 6>()
3 numerical_features = dtype[dtype == 'int64'].index
4 categorical_features = dtype[dtype == 'object'].index
----> 6 readable_df[numerical_features].describe()
File ~/python-env/python-env/lib/python3.9/site-packages/pandas/core/generic.py:10227, in NDFrame.describe(self, percentiles, include, exclude, datetime_is_numeric)
9978 @final
9979 def describe(
9980 self: NDFrameT,
(...)
9984 datetime_is_numeric=False,
9985 ) -> NDFrameT:
9986 """
9987 Generate descriptive statistics.
9988
(...)
10225 max NaN 3.0
10226 """
> 10227 return describe_ndframe(
10228 obj=self,
10229 include=include,
10230 exclude=exclude,
10231 datetime_is_numeric=datetime_is_numeric,
10232 percentiles=percentiles,
10233 )
File ~/python-env/python-env/lib/python3.9/site-packages/pandas/core/describe.py:87, in describe_ndframe(obj, include, exclude, datetime_is_numeric, percentiles)
82 describer = SeriesDescriber(
83 obj=cast("Series", obj),
84 datetime_is_numeric=datetime_is_numeric,
85 )
86 else:
---> 87 describer = DataFrameDescriber(
88 obj=cast("DataFrame", obj),
89 include=include,
90 exclude=exclude,
91 datetime_is_numeric=datetime_is_numeric,
92 )
94 result = describer.describe(percentiles=percentiles)
95 return cast(NDFrameT, result)
File ~/python-env/python-env/lib/python3.9/site-packages/pandas/core/describe.py:164, in DataFrameDescriber.__init__(self, obj, include, exclude, datetime_is_numeric)
161 self.exclude = exclude
163 if obj.ndim == 2 and obj.columns.size == 0:
--> 164 raise ValueError("Cannot describe a DataFrame without columns")
166 super().__init__(obj, datetime_is_numeric=datetime_is_numeric)
ValueError: Cannot describe a DataFrame without columns