Difference between revisions of "Pandas"
Jump to navigation
Jump to search
Rafahsolis (talk | contribs) m (→Dataframe) Tag: visualeditor |
Rafahsolis (talk | contribs) m (→Info) Tag: visualeditor |
||
| Line 6: | Line 6: | ||
==Read CSV== | ==Read CSV== | ||
<syntaxhighlight lang="python3"> | <syntaxhighlight lang="python3"> | ||
| − | + | df = pd.read_csv('news_2019.05.10.csv') | |
</syntaxhighlight> | </syntaxhighlight> | ||
==Dataframe== | ==Dataframe== | ||
| − | === Info === | + | ===Info=== |
<syntaxhighlight lang="python3"> | <syntaxhighlight lang="python3"> | ||
| − | + | df.index | |
| − | + | df.columns | |
| − | + | df.values | |
| + | df.head() | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Select 1 row=== | ===Select 1 row=== | ||
<syntaxhighlight lang="python3"> | <syntaxhighlight lang="python3"> | ||
| − | + | df.iloc[[1]] | |
</syntaxhighlight> | </syntaxhighlight> | ||
===Select 1 column=== | ===Select 1 column=== | ||
<syntaxhighlight lang="python3"> | <syntaxhighlight lang="python3"> | ||
| − | sumarys = | + | sumarys = df[['summary']] |
# Or | # Or | ||
list(df['one']) | list(df['one']) | ||
| Line 33: | Line 34: | ||
===Select 1 cell=== | ===Select 1 cell=== | ||
<syntaxhighlight lang="python3"> | <syntaxhighlight lang="python3"> | ||
| − | + | df.iloc[1][1] | |
# Or | # Or | ||
| − | + | df.iloc[1]['summary'] | |
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Python]] | [[Category:Python]] | ||
Revision as of 06:54, 21 May 2019
Install
pip install pandas
Read CSV
df = pd.read_csv('news_2019.05.10.csv')
Dataframe
Info
df.index
df.columns
df.values
df.head()
Select 1 row
df.iloc[[1]]
Select 1 column
sumarys = df[['summary']]
# Or
list(df['one'])
dfToList = df['one'].tolist()
Select 1 cell
df.iloc[1][1]
# Or
df.iloc[1]['summary']