Jack Noob
Jack Noob

Reputation: 105

Python - Convert particular columns of data to integer

I have a 2d array that is stored with NumPy. Is it possible to only convert the first and second columns to integers from float?

This is my example of a 2d array.

2D array

Upvotes: -1

Views: 118

Answers (1)

Overcode
Overcode

Reputation: 140

You can use asType() method

import numpy as np

arrayOfFloats = np.array(
    [
        [1.2, 2.2, 3.2],
        [4.3, 5.4, 6.2]
    ]
)

arrayOfFloats[0:1, 0:2] = arrayOfFloats[0:1, 0:2].astype(np.int64)

print(arrayOfFloats)

Upvotes: 2

Related Questions