Download presentation
Presentation is loading. Please wait.
1
雲端計算
2
Pandas Python3.5 functions
3
Pandas
4
install pandas pip install pandas
5
Series import pandas as pd
s1=pd.Series(['San Francisco', 'San Jose', 'Sacramento']) print(s1)
6
Dataframe import pandas as pd
city_names = pd.Series(['San Francisco', 'San Jose', 'Sacramento']) population = pd.Series([852469, , ]) d1=pd.DataFrame({ 'City name': city_names, 'Population': population }) print(d1)
7
dataframe.describe() import pandas as pd
california_housing_dataframe = pd.read_csv(" sep=",") california_housing_dataframe.describe()
8
dataframe.head() import pandas as pd
california_housing_dataframe = pd.read_csv(" sep=",") print(california_housing_dataframe.head())
9
dataframe.hist() import pandas as pd
california_housing_dataframe = pd.read_csv(" sep=",") california_housing_dataframe.hist('housing_median_age')
10
Accessing Data import pandas as pd
city_names = pd.Series(['San Francisco', 'San Jose', 'Sacramento']) population = pd.Series([852469, , ]) cities=pd.DataFrame({ 'City name': city_names, 'Population': population }) print(type(cities['City name'])) d1=cities['City name'] print(d1)
11
Accessing Data import pandas as pd
city_names = pd.Series(['San Francisco', 'San Jose', 'Sacramento']) population = pd.Series([852469, , ]) cities=pd.DataFrame({ 'City name': city_names, 'Population': population }) print(type(cities['City name'][1])) print(cities['City name'][1]) print() print(type(cities[0:2])) print(cities[0:2])
12
Manipulating Data import pandas as pd import numpy as np
city_names = pd.Series(['San Francisco', 'San Jose', 'Sacramento']) population = pd.Series([852469, , ]) cities = pd.DataFrame({ 'City name': city_names, 'Population': population }) print("population: ") print(population) print() print(population / 1000.) p1=np.log(population) print(p1) p2=population.apply(lambda val: val > ) print(p2)
13
Manipulating Data print(cities) print()
cities['Area square miles'] = pd.Series([46.87, , 97.92]) cities['Population density'] = cities['Population'] / cities['Area square miles'] pd.options.display.max_columns=5
14
驗收 Adding a new boolean column that is True if the city has an area greater than 50 square miles.
15
驗收 import pandas as pd city_names = pd.Series(['San Francisco', 'San Jose', 'Sacramento']) population = pd.Series([852469, , ]) cities = pd.DataFrame({ 'City name': city_names, 'Population': population }) cities['Area square miles'] = pd.Series([46.87, , 97.92]) cities['Population density'] = cities['Population'] / cities['Area square miles'] pd.options.display.max_columns=5 print(cities) print()
16
Python3.5 functions
17
程序 (subroutines or procedures)
擁有特定功能的獨立程式單元
18
函數 (functions) 程序如果有傳回值,稱為函數
19
函數 (functions)
20
函數 (functions)
21
函數 (functions) 寫一個函數,並定義一個數列的第n項為前2項之和 輸入一個數字m,並印出該數列及數列的的第m項
22
驗收 輸入一個數字n,將1到n加總後,將結果回傳給主程式並印出。
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.