簡體   English   中英

python/pandas 加載 csv 文件時“內核已死,正在重新啟動”

[英]python/pandas "Kernel died, restarting" while loading a csv file

在嘗試加載一個大的 csv 文件 (150 MB) 時,我收到錯誤“內核已死,正在重新啟動”。 然后我使用的唯一代碼如下:

import pandas as pd
from pprint import pprint
from pathlib import Path
from datetime import date
import numpy as np
import matplotlib.pyplot as plt

basedaily = pd.read_csv('combined_csv.csv')

以前它可以工作,但我不知道為什么它不再工作了。 我嘗試使用 engine="python" 修復它,如下所示:

basedaily = pd.read_csv('combined_csv.csv', engine='python')

但它給了我一個錯誤執行中止。

歡迎任何幫助!

提前致謝!

可能是因為內存不足導致出現此錯誤。 您可以在許多數據框中拆分數據,完成工作而不是重新合並它們,下面是一些您可能會使用的有用代碼:

import pandas as pd

# the number of row in each data frame
# you can put any value here according to your situation
chunksize = 1000

# the list that contains all the dataframes
list_of_dataframes = []

for df in pd.read_csv('combined_csv.csv', chunksize=chunksize):
    # process your data frame here
    # then add the current data frame into the list
    list_of_dataframes.append(df)

# if you want all the dataframes together, here it is
result = pd.concat(list_of_dataframes)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM