Skip to main content
improve format, update link
Source Link
cottontail
  • 24.2k
  • 25
  • 171
  • 166

Can someone explain how these two methods of slicing are different?
I've I've seen the docs,the docs and I've seen previous similar questions (these1, answers2), but I still find myself unable to understand how the threethey are different. To me, they seem interchangeable in large part, because they are at the lower levels of slicing.

For example, say we want to get the first five rows of a DataFrame. How is it that these two work?

df.loc[:5]
df.iloc[:5]
df.loc[:5]
df.iloc[:5]

Can someone present three cases where the distinction in uses are clearer?


Once upon a time, I also wanted to know how these two functions differdiffered from df.ix[:5] but ix has been removed from pandas 1.0, so I don't care anymore.

Can someone explain how these two methods of slicing are different?
I've seen the docs, and I've seen these answers, but I still find myself unable to understand how the three are different. To me, they seem interchangeable in large part, because they are at the lower levels of slicing.

For example, say we want to get the first five rows of a DataFrame. How is it that these two work?

df.loc[:5]
df.iloc[:5]

Can someone present three cases where the distinction in uses are clearer?


Once upon a time, I also wanted to know how these two functions differ from df.ix[:5] but ix has been removed from pandas 1.0, so I don't care anymore.

Can someone explain how these two methods of slicing are different? I've seen the docs and I've seen previous similar questions (1, 2), but I still find myself unable to understand how they are different. To me, they seem interchangeable in large part, because they are at the lower levels of slicing.

For example, say we want to get the first five rows of a DataFrame. How is it that these two work?

df.loc[:5]
df.iloc[:5]

Can someone present cases where the distinction in uses are clearer?


Once upon a time, I also wanted to know how these two functions differed from df.ix[:5] but ix has been removed from pandas 1.0, so I don't care anymore.

edited tags
Link
Henry Ecker
  • 35.7k
  • 19
  • 47
  • 64
added 2 characters in body
Source Link
lmiguelvargasf
  • 70.3k
  • 54
  • 228
  • 237

Can someone explain how these two methods of slicing are different?
I've seen the docs, and I've seen these answers, but I still find myself unable to explainunderstand how the three are different. ToTo me, they seem interchangeable in large part, because they are at the lower levels of slicing.

For example, say we want to get the first five rows of a DataFrame. How is it that these two work?

df.loc[:5]
df.iloc[:5]

Can someone present three cases where the distinction in uses are clearer?


Once upon a time, I also wanted to know how these two functions differ from df.ix[:5] but ix has been removed from pandas 1.0, so I don't care anymore!.

Can someone explain how these two methods of slicing are different?
I've seen the docs, and I've seen these answers, but I still find myself unable to explain how the three are different. To me, they seem interchangeable in large part, because they are at the lower levels of slicing.

For example, say we want to get the first five rows of a DataFrame. How is it that these two work?

df.loc[:5]
df.iloc[:5]

Can someone present three cases where the distinction in uses are clearer?


Once upon a time, I also wanted to know how these two functions differ from df.ix[:5] but ix has been removed from pandas 1.0, so I don't care anymore!

Can someone explain how these two methods of slicing are different?
I've seen the docs, and I've seen these answers, but I still find myself unable to understand how the three are different. To me, they seem interchangeable in large part, because they are at the lower levels of slicing.

For example, say we want to get the first five rows of a DataFrame. How is it that these two work?

df.loc[:5]
df.iloc[:5]

Can someone present three cases where the distinction in uses are clearer?


Once upon a time, I also wanted to know how these two functions differ from df.ix[:5] but ix has been removed from pandas 1.0, so I don't care anymore.

added 151 characters in body; edited title
Source Link
cs95
  • 404.2k
  • 105
  • 739
  • 793
Loading
Notice removed Reward existing answer by cs95
Bounty Ended with Alex Riley's answer chosen by cs95
Notice added Reward existing answer by cs95
Bounty Started worth 150 reputation by cs95
Question Protected by cs95
edited title
Link
nbro
  • 15.9k
  • 34
  • 120
  • 214
Loading
edited title
Link
AZhao
  • 14.5k
  • 8
  • 32
  • 55
Loading
Rollback to Revision 6
Link
AZhao
  • 14.5k
  • 8
  • 32
  • 55
Loading
edited title
Link
nbro
  • 15.9k
  • 34
  • 120
  • 214
Loading
state the question
Link
smci
  • 34k
  • 21
  • 117
  • 152
Loading
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot
Loading
edited tags
Link
Alex Riley
  • 177.4k
  • 46
  • 272
  • 245
Loading
edited tags
Link
Alex Riley
  • 177.4k
  • 46
  • 272
  • 245
Loading
edited title
Link
Alex Riley
  • 177.4k
  • 46
  • 272
  • 245
Loading
Source Link
AZhao
  • 14.5k
  • 8
  • 32
  • 55
Loading