Pandas series

You can have a serie like this in pandas

import pandas as pd

s = pd.Series([1,2,3])

The output being this

0    1                                                
1    2                                                
2    3

You can use index and have this change

s = pd.Series([1,2,3],
	index=["day 1", "day 2", "day 3"])

that is

day 1    1                                            
day 2    2                                            
day 3    3

Choose only one row

print(s["day 3"])

The output will be

3

Using a dictionary as values of the serie

import pandas as pd

values = {
		"day 1": 1,
		"day 2": 2,
		"day 3": 3}

s = pd.Series(values)

the output

day 1    1
day 2    2
day 3    3

Using numpy and arange

import pandas as pd
import numpy as np

a = np.arange(9)

s = pd.Series(a)

output

0    0
1    1
2    2
3    3
4    4
5    5
6    6
7    7
8    8

another way

import pandas as pd
import numpy as np

a = np.arange(9)

s = pd.Series(1, index=a)

the output will be

0    1
1    1
2    1
3    1
4    1
5    1
6    1
7    1
8    1

 

Advertisement