I have a pandas dataframe (can convert it to numpy array if it's better) like this:
And I would like to convert each value from strings to numeric
I have tried to use things like convert objects
but it doesn't work at all. I think the problem are the square brackets so the function would work If i can get rid of them.
Greetings and thanks in advance
Edit:
Here is where the data comes from
X_ans=[]
Y_ans=[]
for i in range (len(data["Births"])-2):
X=list(data["Births"])[i:i+3]
Y=list(data["Births"])[i+1]
X_ans.append(X)
Y_ans.append(Y)
in_=pd.DataFrame([ str(x) for x in X_ans ],columns=['input'])
out=pd.DataFrame([ str(x) for x in Y_ans ],columns=['output'])
ans_1=pd.concat([in_,out],axis=1)
ans_1 would be like that:
Now I split it:
msk = np.random.rand(len(ans_1)) < 0.8
traindf = ans_1[msk]
evaldf = ans_1[~msk]
And split the values which are separated by commas to get the dimensions
X_train = traindf.iloc[:, 0]
Y_train = traindf.iloc[:, 1]
X_test = evaldf.iloc[:, 0]
Y_test = evaldf.iloc[:, 1]
X_train = X_train.str.split(pat = ',', expand = True)
X_train = X_train.values
X_test = X_test.str.split(pat = ',', expand = True)
X_test = X_test.values
PS:I can use values: