Changes

Jump to navigation Jump to search
363 bytes added ,  10:17, 21 May 2019
m
Line 25: Line 25:  
===Select 1 row===
 
===Select 1 row===
 
<syntaxhighlight lang="python3">
 
<syntaxhighlight lang="python3">
df.iloc[[1]]
+
df.iloc[[1]] # for positional indexing
df.loc[0]
+
df.loc[0]   # for label based
 
df.iloc[-1] == df.loc[df.shape[0]-1]
 
df.iloc[-1] == df.loc[df.shape[0]-1]
 +
</syntaxhighlight>
 +
 +
=== Select specific rows ===
 +
<syntaxhighlight lang="python3">
 +
df.loc[[9, 99, 999]]
 
</syntaxhighlight>
 
</syntaxhighlight>
   Line 46: Line 51:  
<syntaxhighlight lang="python3">
 
<syntaxhighlight lang="python3">
 
df.iloc[1][1]
 
df.iloc[1][1]
# Or
   
df.iloc[1]['summary']
 
df.iloc[1]['summary']
 +
df.iloc[1, 3]
 +
 +
df.loc[1, 'summary']
 +
</syntaxhighlight>
 +
 +
=== Subset multiple rows and multiple columns ===
 +
<syntaxhighlight lang="python3">
 +
df.iloc[[1,34,56],[2,4,5]]
 +
df.loc[[1,34,56],['modification_date', 'content']]
 
</syntaxhighlight>
 
</syntaxhighlight>
 
[[Category:Python]]
 
[[Category:Python]]

Navigation menu