Difference between revisions of "Pandas"

From RHS Wiki
Jump to navigation Jump to search
m
Tag: visualeditor
m
Tag: visualeditor
Line 9: Line 9:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
== Dataframe ==
+
==Dataframe==
  
=== Select 1 row ===
+
===Select 1 row===
 
<syntaxhighlight lang="python3">
 
<syntaxhighlight lang="python3">
 
texts.iloc[[1]]
 
texts.iloc[[1]]
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== Select 1 column ===
+
===Select 1 column===
 
<syntaxhighlight lang="python3">
 
<syntaxhighlight lang="python3">
 
sumarys = news[['summary']]
 
sumarys = news[['summary']]
 +
</syntaxhighlight>
 +
 +
=== Select 1 cell ===
 +
<syntaxhighlight lang="python3">
 +
texts.iloc[1][1]
 +
# Or
 +
texts.iloc[1]['summary']
 
</syntaxhighlight>
 
</syntaxhighlight>
 
[[Category:Python]]
 
[[Category:Python]]

Revision as of 08:26, 16 May 2019

Install

pip install pandas

Read CSV

news = pd.read_csv('news_2019.05.10.csv')

Dataframe

Select 1 row

texts.iloc[[1]]

Select 1 column

sumarys = news[['summary']]

Select 1 cell

texts.iloc[1][1]
# Or
texts.iloc[1]['summary']