简体   繁体   中英

Python kernel dies while doing a division in Pandas

I have a csv the size is about 94.4 MB and it contains 143,940 rows and 63 columns. I am just trying to divide two columns and outputting the value in another column. The code I am executing is a very simple code.

DF['Col3'] = DF['Col1'] / DF['Col2']

Every time I execute this piece of code on my spyder3 or Jupyter Notebook the kernel dies I used to execute this code before but I dint have any problem. Now I get the error message

Kernel died, restarting

I am running python 2.7 and anaconda version 4.3.14 pandas version 0.19.2 on my laptop which has a 8 GB RAM. of which only 1 GB is utilized prior to running this code and utilizes 100% when I am running this code.

If there are any suggestions please guide. Thank you

I found a solution here: https://www.coursera.org/learn/python-data-analysis/discussions/weeks/4/threads/VrKtIe-TEeahuQ5PjaKRFg

Apparently the kernel has issues with division between two series when there are NaNs involved. I solved the issue by replacing the "/" operator with the div() method as suggested.

Instead of doing df.col1 / df.col2 , you can do df.col1.div(df.col2)

http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.div.html https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.div.html

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM