I wish to have an int matrix which has only its first column filled and the rest of elements are Null. Sorry but, I have a background of R. So, I know if I leave some Null elements it would be easier to manage them later. Meanwhile, if I leave 0 then it would be lots of problems later.
I have the following code:
import numpy as np
import numpy.random as random
import pandas as pa
def getRowData():
rowDt = np.full((80,20), np.nan)
rowDt[:,0] = random.choice([1,2,3],80) # Set the first column
return rowDt
I wish that this function returns the int, but seems that it gives me float.
I have seen this link, and tried the below code:
return pa.to_numeric(rowDt)
But, it did not help me. Also the rowDT object does not have .astype(<type>).
How can I convert an int array?
np.random.choicethe choice function in the random module does not accept a second argument. Also, if rowDT has np.nan in it then it cannot be a integer array as np.nan cannot be represetned by integers. Would that explain it?np.nan_to_numbut then you'd either use a different value forfullin the first place, or you presumably neednanin which case the array cannot be of typeint.astype(<type>)function (version 1.14.3) and I was able to convert it toint, which version are you using?1.15.4intdtype withnull, i.e.nan