question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KeyError: 'min' when generating report structure

See original GitHub issue

Getting KeyError: ‘min’ in the generate report structure step.

I am unable to share the dataframe as it is confidential. The dataframe structure however is:

Int64Index: 425876 entries, 0 to 425875
Data columns (total 20 columns):
    Column                  Non-Null Count   Dtype         
---  ------                  --------------   -----         
 0   dummy_claimid           425876 non-null  int64         
 1   POApprovalNumber        425876 non-null  int64         
 2   VendorId                413820 non-null  float64       
 3   POCreationDate          425876 non-null  datetime64[ns]
 4   POApprovalLineId        425876 non-null  int64         
 5   POLineCreationDate      425875 non-null  datetime64[ns]
 6   dummy_referalid         425876 non-null  object        
 7   serviceFG               425876 non-null  object        
 8   serviceaccount          425876 non-null  object        
 9   serviceAG               425876 non-null  object        
 10  VendorName              413816 non-null  object        
 11  serviceitem             425876 non-null  object        
 12  days_PO2accidate        425876 non-null  int64         
 13  days_PO2lodgdate        425876 non-null  int64         
 14  had_ACC883_inLast7days  425876 non-null  int64         
 15  had_ACC884_inLast7days  425876 non-null  int64         
 16  POLineStatus            425749 non-null  object        
 17  POLineAuthDate          424760 non-null  datetime64[ns]
 18  POLineCancDate          0 non-null       datetime64[ns]
 19  POLineDecDate           41 non-null      datetime64[ns]
dtypes: datetime64[ns](5), float64(1), int64(7), object(7)
memory usage: 68.2+ MB
None```

Output:
```Summarize dataset: 100%
33/33 [00:46<00:00, 1.40s/it, Completed]
Generate report structure: 0%
0/1 [00:06<?, ?it/s]

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~\anaconda3\envs\my_env\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
    343             method = get_real_method(obj, self.print_method)
    344             if method is not None:
--> 345                 return method()
    346             return None
    347         else:

~\anaconda3\envs\my_env\lib\site-packages\pandas_profiling\profile_report.py in _repr_html_(self)
    434     def _repr_html_(self):
    435         """The ipython notebook widgets user interface gets called by the jupyter notebook."""
--> 436         self.to_notebook_iframe()
    437 
    438     def __repr__(self):

~\anaconda3\envs\my_env\lib\site-packages\pandas_profiling\profile_report.py in to_notebook_iframe(self)
    414         with warnings.catch_warnings():
    415             warnings.simplefilter("ignore")
--> 416             display(get_notebook_iframe(self))
    417 
    418     def to_widgets(self):

~\anaconda3\envs\my_env\lib\site-packages\pandas_profiling\report\presentation\flavours\widget\notebook.py in get_notebook_iframe(profile)
     63         output = get_notebook_iframe_src(profile)
     64     elif attribute == "srcdoc":
---> 65         output = get_notebook_iframe_srcdoc(profile)
     66     else:
     67         raise ValueError(

~\anaconda3\envs\my_env\lib\site-packages\pandas_profiling\report\presentation\flavours\widget\notebook.py in get_notebook_iframe_srcdoc(profile)
     21     width = config["notebook"]["iframe"]["width"].get(str)
     22     height = config["notebook"]["iframe"]["height"].get(str)
---> 23     src = html.escape(profile.to_html())
     24 
     25     iframe = f'<iframe width="{width}" height="{height}" srcdoc="{src}" frameborder="0" allowfullscreen></iframe>'

~\anaconda3\envs\my_env\lib\site-packages\pandas_profiling\profile_report.py in to_html(self)
    384 
    385         """
--> 386         return self.html
    387 
    388     def to_json(self) -> str:

~\anaconda3\envs\my_env\lib\site-packages\pandas_profiling\profile_report.py in html(self)
    199     def html(self):
    200         if self._html is None:
--> 201             self._html = self._render_html()
    202         return self._html
    203 

~\anaconda3\envs\my_env\lib\site-packages\pandas_profiling\profile_report.py in _render_html(self)
    306         from pandas_profiling.report.presentation.flavours import HTMLReport
    307 
--> 308         report = self.report
    309 
    310         disable_progress_bar = not config["progress_bar"].get(bool)

~\anaconda3\envs\my_env\lib\site-packages\pandas_profiling\profile_report.py in report(self)
    193     def report(self):
    194         if self._report is None:
--> 195             self._report = get_report_structure(self.description_set)
    196         return self._report
    197 

~\anaconda3\envs\my_env\lib\site-packages\pandas_profiling\report\structure\report.py in get_report_structure(summary)
    245             ),
    246             Container(
--> 247                 render_variables_section(summary),
    248                 sequence_type="accordion",
    249                 name="Variables",

~\anaconda3\envs\my_env\lib\site-packages\pandas_profiling\report\structure\report.py in render_variables_section(dataframe_summary)
    100 
    101         # Per type template variables
--> 102         template_variables.update(render_map[summary["type"]](template_variables))
    103 
    104         # Ignore these

~\anaconda3\envs\my_env\lib\site-packages\pandas_profiling\report\structure\variables\render_date.py in render_date(summary)
     61     table2 = Table(
     62         [
---> 63             {"name": "Minimum", "value": summary["min"], "fmt": "fmt", "alert": False},
     64             {"name": "Maximum", "value": summary["max"], "fmt": "fmt", "alert": False},
     65         ]

KeyError: 'min ```

Code used:
```pandas_profiling.ProfileReport(PO)```

Version information: 
Python version: 3.9.2
Environment: Jupyter Lab
Pandas profiling: 2.11.0

Additional context: I don't have much experience but I think the problem may be that the code cannot calculate the min for datetime objects. Previous versions were able to do this but they are no longer able to summarise the results with this dataset.

Thanks for the help in advance!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
sbrugmancommented, Apr 16, 2021

Thanks for reporting. I suspect the error is caused by POLineCancDate having 0 non-null values.

0reactions
ktavabicommented, Aug 30, 2022

I am getting KeyError: 'data' for a frame without any zero-non-null counts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python KeyError Exceptions and How to Handle Them
Python's official documentation says that the KeyError is raised when a mapping key is accessed and isn't found in the mapping. A mapping...
Read more >
How to fix Python KeyError Exceptions in simple steps?
A Python KeyError is raised when you try to access an invalid key in a dictionary. In simple terms, when you see a...
Read more >
KeyError when creating new column in python pandas
I am trying to create a new column in python pandas, and I keep getting an (unsteady) reoccurring KeyError. The section of the...
Read more >
How to Fix: KeyError in Pandas - GeeksforGeeks
Usually, this error occurs when you misspell a column/row name or include an unwanted space before or after the column/row name.
Read more >
(<type 'exceptions.KeyError'>, KeyError('report',) in odoo 10
Can not create printed report (qWeb PDF). I've created primitive module for test with one model ' _testrep.rent ' with one field '...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found