DataCamp Python Notes
1. Writing your own functions
-
Docstrings:
functions 內開頭最好習慣寫說明。
-
Unpacking tuples:
2. Default arguments, variable-length arguments and scope
-
Global vs. local scope
-
Nested functions:
-
Returning functions:
-
Using nonlocal:
-
*args:
-
**kwargs:
3. Lambda functions and error-handling
-
Anonymous functions:
map() applies the function to ALL elements in the sequence
-
Errors and exceptions:
1. Using iterators in PythonLand
-
Iterators vs. iterables:
- Iterable
- Examples: lists, strings, dictionaries, file connections
- An object with an associated iter() method
- Applying iter() to an iterable creates an iterator
- Iterator
- Produces next value with next()
-
Iterating over iterables: next():
-
Iterating at once with *:
-
Iterating over dictionaries:
-
Using enumerate():
-
Using zip():
-
Using iterators for big data:
2. List comprehensions
1. Exploring your data
2. Tidying data for analysis
3. Combining data for analysis
-
row bind
要記得處理 index
-
合併分割檔
4. Cleaning data for analysis
-
轉換格式
轉成 category 可減少記憶體用量,亦可用於某些套件的分析
-
計算 rows/columns 平均
-
apply function

-
assert
用來確認資料是我們要的樣子
1. Data ingestion & inspection
-
slicing:
-
Series:
-
DataFrames from dict:
-
read_csv:
-
Using dates as index:
-
Ploting Series:
-
Fixing scales:
-
Customizing plots:
-
Saving plots:
2. Exploratory data analysis
-
Line/Scatter/Box/Histogram plot:
-
Statistical exploratory data analysis:
-
探索類別變項:
3. Time series in pandas
-
Parse dates:
-
selection:
-
Convert strings to datetime: