0

I want to select only a row index 140088. As you can see in the picture, I cannot see the whole sentence. I want to see the whole sentence so that I can copy that and translate it. However, I have difficulty extracting only one row with iloc.

enter image description here

Genie
  • 41
  • 6

3 Answers3

3

The problem is that .iloc returns the item in the given position, most of the time the index reflects the position of the item you are getting in the DataFrame, which is not your situation, since you have index 140088 in a DataFrame with 11126 items.

There are two solutions though, the first is the easier in most situations, you just .reset_index of your DataFrame, then it creates an index that resembles the data.

The other solution is using the .loc method, as

reviews_neg.loc[reviews_neg.index == 140088]
Aislan
  • 81
  • 1
  • 3
1

reviews_neg.iloc[[140088]] should do the trick.

More details can be found in this question: Selecting a row of pandas series/dataframe by integer index

Timm Nicolaizik
  • 357
  • 1
  • 11
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 15 '22 at 00:57
1

If you want to select a row and have it in the shape of a dataframe you can do something like:

reviews_neg.iloc[140087:140088,:]

Also, what @TimmNocolaizik said works fine. If you use reviews_neg.iloc[140088], it won't result in a dataframe shape, rather a Series (I guess).

TheFaultInOurStars
  • 3,464
  • 1
  • 8
  • 29
  • @Amirhossenin Kiani When I typed `reviews_neg.iloc[140088:140089,:]` as your comment, there was no error but the result just showed the column names (Review, Label) without values... What can I do?... – Genie Mar 14 '22 at 20:31
  • @Genie Are you sure that these values are indices? I mean, what would it result if you run this code? `reviews_neg.index`. Does it print a dataframe, containing `7, 13, 17, 19, ...`? – TheFaultInOurStars Mar 14 '22 at 20:33
  • I can see this result. Int64Index([ 7, 13, 17, 19, 48, 49, 52, 60, 61, 64, ... 140068, 140071, 140073, 140074, 140075, 140088, 140114, 140143, 140212, 140237], dtype='int64', length=11126) – Genie Mar 14 '22 at 20:50
  • @Genie I am not sure, but I have edited my answer.(I have changed the `140088` to `140087`). Take a look and try it. See whether it is the solution to your problem or not (I hope it is). – TheFaultInOurStars Mar 14 '22 at 20:53
  • 1
    I found that I made mistake;;^^ there are 11126 rows. 140088 is the index number but I can count it as 140088th. Thank you for trying to solve and help me! – Genie Mar 14 '22 at 21:02