Convert 2D numpy.ndarray to pandas.DataFrame
By : Anwaar
Date : March 29 2020, 07:55 AM
I hope this helps . I suspect your ndarr, if expressed as a 2d np.array, always has the shape of n,m, where n is the length of cache1.id1 and m is the length of cache2.id2. And the last entry in cache2, should be {'id2': 38472837} instead of {'id': 38472837}. If so, the following simple solution may be all what is needed: code :
In [30]:
df=pd.DataFrame(np.array(ndarr).ravel(),
index=pd.MultiIndex.from_product([cache1.id1.values, cache2.id2.values],names=['idx1', 'idx2']),
columns=['val'])
In [33]:
print df.reset_index()
idx1 idx2 val
0 ABC1234 3276827 4.3
1 ABC1234 98567498 5.6
2 ABC1234 38472837 6.7
3 NCMN7838 3276827 3.2
4 NCMN7838 98567498 4.5
5 NCMN7838 38472837 2.1
[6 rows x 3 columns]

Convert a numpy.ndarray to string(or bytes) and convert it back to numpy.ndarray
By : user3621682
Date : March 29 2020, 07:55 AM
To fix this issue I'm having a little trouble here, , You can use the fromstring() method for this: code :
arr =np.array([1,2,3,4,5,6])
ts = arr.tostring()
print np.fromstring(ts,dtype=int)
>>>[1 2 3 4 5 6]

Convert pandas nested Series into Numpy ndarray
By : user3486564
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I have a pandas DataFrame that looks like this: , Try this, it should strip the brackets and create the double array: code :
def reshape_array_string(x):
temp = x.replace('[', '').replace(']','').replace(',','').split(" ")
shapelen = len(temp)//2
return (np.reshape(temp, [shapelen,2]))
df['Count'].apply(reshape_array_string)
0 [[20.0, 38.5], [3.2, 8.5]]
1 [[3.7, 8.2], [5.7, 5.5], [4.6, 2.2]]

Convert pandas sparse dataframe to sparse numpy matrix for sklearn use?
By : scottM
Date : March 29 2020, 07:55 AM
To fix the issue you can do You should be able to use the experimental .to_coo() method in pandas [1] in the following way:

keras : converting numpy ndarray of strings to numpy ndarray of floats :: ValueError: could not convert string to float:
By : nallen718
Date : March 29 2020, 07:55 AM
it fixes the issue Assuming that the Y values are intended to be 'yes'/1... Use numpy.where to cast the 'Y' values to 1: code :
X = np.where(X=='Y', 1, X)

