numpy.ndarray.tolist will do it:
a.tolist()
If your data is a pandas series you can call their tolist wrapper with the same result.
Answer from bigonazzi on Stack OverflowHow to convert python int into numpy.int64? - Stack Overflow
np.int64 and np.uint64 casting to int creates an overflow with large numbers
Int64 to Int on Otree survey
to_dict doesn't convert np.int64 to python integers
Given a variable in python of type int, e.g.
z = 50 type(z) ## outputs <class 'int'>
is there a straightforward way to convert this variable into numpy.int64?
It appears one would have to convert this variable into a numpy array, and then convert this into int64. That feels quite convoluted.
https://docs.scipy.org/doc/numpy-1.13.0/user/basics.types.html
z_as_int64 = numpy.int64(z)
It's that simple. Make sure you have a good reason, though - there are a few good reasons to do this, but most of the time, you can just use a regular int directly.
import numpy as np
z = 3
z = np.dtype('int64').type(z)
print(type(z))
outputs:
<class 'numpy.int64'>
But i support Juliens question in his comment.
You can try by doing df["Bare Nuclei"].astype(np.int64) but as far as I can see the problem is something else. Pandas first reads all the data to best estimate the data type for each column, then only makes the data frame. So, there must be some entries in the data frame which are not integer types, i.e., they may contain some letters. In that case, also typecasting should give an error. So you need to remove those entries before successfully making the table integer.
I had the same problem with the same dataset.
There are lots of "?" in the data for the 'bare_nuclei' column (16) of them in the csv itself you need to use the error handling to drop the rows with the ? in the bare_nuclei column, also as a heads up don't name 'class' column class as that's a reserved keyword in python and that's also going to cause problems later.
You can fix this at import using:
missing_values = ["NA","N/a",np.nan,"?"]
l1 = pd.read_csv("../DataSets/Breast cancer dataset/breast-cancer-wisconsin.data",
header=None, na_values=missing_values,
names=['id','clump_thickness','uniformity_of_cell_size',
'uniformity_of_cell_shape', 'marginal_adhesion',
'single_epithelial_cell_size', 'bare_nuclei', 'bland_chromatin',
'normal_nucleoli', 'mitoses', 'diagnosis'])
l1 = l1.dropna()