Changes
Jump to navigation
Jump to search
← Older edit
Newer edit →
Pandas
(edit)
Revision as of 10:17, 21 May 2019
363 bytes added
,
10:17, 21 May 2019
m
→Select 1 row
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]]
Rafahsolis
Bureaucrats
,
Administrators
2,306
edits
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
Variants
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
Special pages
Printable version