Difference between revisions of "Pandas"

From wiki
Jump to navigation Jump to search
(Created page with "Check the [https://pandas.pydata.org/pandas-docs/stable/10min.html 10 minutes to Pandas] too. ;import pandas as pd :Import the library, we assume this was done on this page ;s...")
 
Line 2: Line 2:
 
;import pandas as pd
 
;import pandas as pd
 
:Import the library, we assume this was done on this page
 
:Import the library, we assume this was done on this page
 +
 +
Pandas Series [https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.html documentation] online. Pandas has all kind of methods similar to [[Numpy]] like main, std, min, max,...
 
;s = pd.Series([])
 
;s = pd.Series([])
 
:Initialize a series
 
:Initialize a series
 +
;s.index
 +
:All indexes in the series
 +
;s.describe()
 +
:Series statistics
  
 
All in 1 example:
 
All in 1 example:
Line 12: Line 18:
 
for i in range(50):
 
for i in range(50):
 
     s[i] = int(np.random.random() * 100)
 
     s[i] = int(np.random.random() * 100)
 +
 +
for i in s.index:
 +
    print(i,s[i])
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 23: Line 32:
 
for v in s:
 
for v in s:
 
     print(v)
 
     print(v)
 +
</syntaxhighlight>
 +
To get the indexes too:
 +
<syntaxhighlight lang=python>
 +
for i in s.index:
 +
    print(i,s[i])
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 18:40, 15 December 2018

Check the 10 minutes to Pandas too.

import pandas as pd
Import the library, we assume this was done on this page

Pandas Series documentation online. Pandas has all kind of methods similar to Numpy like main, std, min, max,...

s = pd.Series([])
Initialize a series
s.index
All indexes in the series
s.describe()
Series statistics

All in 1 example:

import numpy as np
import pandas as pd
s = pd.Series([])
for i in range(50):
    s[i] = int(np.random.random() * 100)

for i in s.index:
    print(i,s[i])

Funny, you can do s[0] but not

for i in s:
    print(s[i])

To get all values from the series you do:

for v in s:
    print(v)

To get the indexes too:

for i in s.index:
    print(i,s[i])