Difference between revisions of "Pandas"

From RHS Wiki
Jump to navigation Jump to search
Tag: visualeditor
Tag: visualeditor
Line 34: Line 34:
 
list(df['one'])
 
list(df['one'])
 
dfToList = df['one'].tolist()
 
dfToList = df['one'].tolist()
 +
</syntaxhighlight>
 +
 +
=== Select multiple columns ===
 +
<syntaxhighlight lang="python3">
 +
df[['column1', 'column2', 'column3']]
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Revision as of 07:20, 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.shape
df.dtypes
df.head()
df.tail()
df.info()

Select 1 row

df.iloc[[1]]

Select 1 column

sumarys = df[['summary']]
# Or
list(df['one'])
dfToList = df['one'].tolist()

Select multiple columns

df[['column1', 'column2', 'column3']]

Select 1 cell

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