20. Try it !
§ #練習: Write a Python program to create and display a
one-dimensional array-like object containing an array of
data using Pandas module.
20
21. Try it !
§ #練習: Write a Python program to convert a Panda
module Series to Python list and it’s type.
21
22. Try it !
§ #練習: Write a Python program to convert a Python
dictionary to Panda module Series and it’s type.
22
23. Access a Series
23
1
2
3
4
5
6
7
import pandas as pd
s = pd.Series([1,2,3,4,5],index = ['a','b','c','d','e'])
#retrieve the first element
print(s.index) # ['a', 'b', 'c', 'd', 'e']
print(s.values) # [1, 2, 3, 4, 5]
24. Access a Series
24
1
2
3
4
5
6
7
8
9
import pandas as pd
s = pd.Series([1,2,3,4,5],index = ['a','b','c','d','e'])
#retrieve the first element
print(s[0]) # 1
print(s['a']) # 1
print(s.get('a')) # 1
25. Access a Series
25
1
2
3
4
5
6
7
8
9
10
11
12
13
import pandas as pd
s = pd.Series([1,2,3,4,5],index = ['a','b','c','d','e'])
#retrieve the first three element
print(s[:3])
print(s[:'c'])
# a 1
# b 2
# c 3
# dtype: int64
39. Try it !
§ #練習: Write a Python program to add, subtract,
multiple and divide two given Pandas Series.
• Sample Input Given: [2, 4, 6, 8, 10], [1, 3, 5, 7, 9]
39
40. Try it !
§ #練習: Write a Python program to add, subtract,
multiple and divide two Pandas Series from user
input.
• Sample Input: [2, 4, 6, 8, 10], [1, 3, 5, 7, 9]
40
41. Try it !
§ #練習: Write a Python program to compare the
elements of the two Pandas Series.
• Sample Input: [2, 4, 6, 8, 10], [1, 3, 5, 7, 9]
41