Wednesday 30 June 2021

pandas- kernel restarting: the kernel for .ipynb appears to have died. it will restart automatically

Update

I ran a docker-container for a jupyter-notebook, however when running a pandas-based block, after a few seconds the system returns:

kernel restarting: the kernel for .ipynb appears to have died. it will restart automatically.

With just the option of restarting the kernel.

Here's the block of code where the message arises:

import pandas as pd


def remove_typos(string):
    
    string=str(string)
    string=str(string).replace('≤', '')
    string=str(string).replace('+', '')
    
    # if "%" detected then convert to numeric format
    if "%" in string: 
        string=string.replace('%', '')
        string=float(string)/100
        
    else:
        pass
        
    return string


data = {k: v.replace([r'\+', '≤'], '', regex=True) for k, v in data.items()}
data = {k: v.applymap(remove_typos) for k, v in data.items()}

  • What I already tried?
  1. I already tried to run pip install pandas in the container cli: Which returns me the next message:

enter image description here

  1. Tried to give more local memory to the container:

enter image description here

  1. Tried to update conda and reinstall all packages from anaconda prompt:
# conda config --set quiet True
# conda update --force conda

#conda install pandas

In all cases, the outcome was the same.

Additional notes:

  • total processor utilization reachs 100%
  • function is applied over 10,000+ cells

Are there any other options to overcome this issue?

data demo

  • Original df keeps same format but is so much bigger in size.
data = {'dataframe_1':pd.DataFrame({'col1': ['John', 'Ashley'], 'col2': ['+10', '-1']}), 'dataframe_2':pd.DataFrame({'col3': ['Italy', 'Brazil', 'Japan'], 'col4': ['Milan', 'Rio do Jaineiro', 'Tokio'], 'percentage':['+95%', '≤0%', '80%+']})}

session info

{'commit_hash': '2486838d9',
 'commit_source': 'installation',
 'default_encoding': 'UTF-8',
 'ipython_path': '/usr/local/lib/python3.6/site-packages/IPython',
 'ipython_version': '7.16.1',
 'os_name': 'posix',
 'platform': 'Linux-5.10.25-linuxkit-x86_64-with-debian-10.9',
 'sys_executable': '/usr/local/bin/python',
 'sys_platform': 'linux',
 'sys_version': '3.6.13 (default, May 12 2021, 16:40:31) \n[GCC 8.3.0]'}


from pandas- kernel restarting: the kernel for .ipynb appears to have died. it will restart automatically

No comments:

Post a Comment