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()}
pip install pandas
in the container cli: Which returns me the next message:# conda config --set quiet True
# conda update --force conda
#conda install pandas
In all cases, the outcome was the same.
Additional notes:
Are there any other options to overcome this issue?
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%+']})}
{'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]'}
The issue was related to the number of iterations, it was necessary to decrease iterations.
First, renamed the function to convert_to_percentage()
, then iterate over each key and value to replace characters:
############# convert_to_percentage(string) #################
# string :: strings which represent a percentage.
def convert_to_percentage(string):
#string=str(string).replace([r'\+', '≤'], '', regex=True)
# if "%" detected then convert to numeric format
if "%" in string:
string=str(string)
string=string.replace('%', '')
string=float(string)/100
else:
pass
return string
############################################################
# #
# removin typos for each string and converting to float #
# #
############################################################
######## removing trailing whitespaces and typos ###########
# for all job title reports
data= {k: v.replace([r'\+', '≤'], '', regex=True) for k, v in data.items()}
print('Succesful removing of typos!')
Second, replace for key, value in data.items()
to for key in data:
############################################################
# #
# conversion of specific columns to percentages (%) #
# #
############################################################
for key in data:
data[key].apply(lambda x: convert_to_percentage(x), axis=1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.