1

I have a variable target_test (for machine learning) and I'd like to display just one element of target_test.

type(target_test) print the following statement on the terminal :

class 'pandas.core.series.Series'

If I do print(target_test) then I get the entire 2 vectors that are displayed.

But I'd like to print just the second element of the first column for example.

So do you have an idea how I could do that ?

I convert target_test to frame or to xarray but it didn't change the error I get.

When I write something like : print(targets_test[0][0])

I got the following output :

TypeError: 'instancemethod' object has no attribute '__getitem__'

4
  • 2
    target_test.iloc[1]? Commented Aug 17, 2018 at 15:47
  • 2
    Think about a pandas series as a dictionnary. The first columns are the keys and the second the values. Therefore targets_test[0] should do the trick. (or targets_test.iloc[0] if you have a custom index). Commented Aug 17, 2018 at 15:51
  • that's working , thank you very much :D , It gaves me the same result that " targets_test.values[i] " answered by tif Commented Aug 17, 2018 at 16:00
  • oups I just saw your comment ysearka , I tried several times targets_test[0] it didn't work but targets_test.iloc[i] and targets_test.values[i] are working for the second column , and targets_test.keys()[i] is working for the first column :) Commented Aug 17, 2018 at 16:03

2 Answers 2

2

the first vector is the index, second one is the the value. to print the first value use target_test[0]

See Indexing and Selecting Data for more information.

>>> import pandas as pd
>>> s=pd.Series({'a':12.3,'b':34.5,'c':45.6})
>>> s
a    12.3
b    34.5
c    45.6
dtype: float64
>>>
>>> s[0]
12.3
>>> s.iloc[0]
12.3
Sign up to request clarification or add additional context in comments.

Comments

1

For the first column, you can use targets_test.keys()[i], for the second one targets_test.values[i] where i is the row starting from 0.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.