[Python] Cannot interpret 'dtype('int64')' in NLP Python Code from adashofdata

Discussão em 'Python' iniciado por Stack, Abril 25, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to run the NLP project shared at https://github.com/adashofdata/nlp-in-python-tutorial, but I am encountering an issue with the code in 4-Topic-Modeling.ipynb. I am running the code on Google Colab and experiencing an error when trying to load the .pkl (pickle) file into the data variable.

    I am looking for suggestions or solutions regarding this issue. I tried pickle, cloudpickle, joblib.

    If there are alternative ways to convert the .pkl file to another format and successfully load it into data, I am open to those suggestions as well.

    Thank you!

    import pickle
    import pandas as pd
    import numpy as np
    from google.colab import drive
    import joblib

    # Mount Google Drive
    drive.mount('/content/drive')

    # File path
    file_path = '/content/drive/MyDrive/Colab Notebooks/pynb/pickle/'

    # Load the file using pickle
    try:
    with open(file_path + 'dtm_stop.pkl', 'rb') as f:
    data = joblib.load(file_path + 'dtm_stop.pkl') # Load using joblib

    # Check the type of the loaded data
    print("Data type:", type(data))

    # If the data type is numpy ndarray, try to convert the dtype
    if isinstance(data, np.ndarray):
    print("Data loaded as numpy ndarray")
    data = data.astype(np.float64, errors='ignore') # Ignore erroneous values
    elif isinstance(data, pd.DataFrame):
    print("Data loaded as DataFrame")
    data = data.apply(pd.to_numeric, errors='coerce') # Convert erroneous values to numeric
    else:
    print("Data is not a DataFrame or numpy array, data type:", type(data))

    except Exception as e:
    print(f"Error loading with pickle: {e}") # Print the error message in more detail
    raise e

    # Let's see the loaded data
    print(data)


    And I took this error messages:

    Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remount=True).
    Error loading with pickle: Cannot interpret 'dtype('int64')' as a data type
    ---------------------------------------------------------------------------
    TypeError Traceback (most recent call last)
    <ipython-input-22-285aaeee691b> in <cell line: 0>()
    30 except Exception as e:
    31 print(f"Error loading with pickle: {e}") # Print the error message in more detail
    ---> 32 raise e
    33
    34 # Let's see the loaded data

    5 frames
    /usr/local/lib/python3.11/dist-packages/numpy/_core/numeric.py in _frombuffer(buf, dtype, shape, order)

    TypeError: Cannot interpret 'dtype('int64')' as a data type

    Continue reading...

Compartilhe esta Página