Why pandas.core.series.Series sometimes cannot convert to torch tensor in Python?
I have a dataframe in which I pick two columns:

X_train, X_test, y_train, y_test = train_test_split(df["EnergyFront"], df["particle"], test_size=0.2) 


the type of both X_train and X_test is pandas.core.series.Series, the results are quite similar:

IMAGE

I can transform X_train to torch tensor:

X_train = torch.Tensor(X_train) 


but, when I try to do the same with X_test:

X_test = torch.Tensor(X_test) 


I get the following error:

ValueError                                Traceback (most recent call last)
&lt;ipython-input-174-14117eb3ce4e&gt; in &lt;module&gt;()
----&gt; 1 X_test = torch.Tensor(X_test)

ValueError: could not determine the shape of object type 'Series'


How can I solve it?
By the way, I am running on Google Colaboratory.

This issue is described here: https://github.com/pytorch/pytorch/pull/7583
In order to determine the shape of the series, they try to access the element with index 0. If that element is not found, this error occurs. In your case, presumably this happens because your X_test doesn't contain the first element of the whole Series. 

I believe a valid fix for your case would be to convert your X_test to an array like so:

X_test = torch.Tensor(X_test.to_numpy())

