zerohertzLib.util.csv ¶
Functions:
| Name | Description |
|---|---|
read_csv | CSV (Comma-Separated Values) 혹은 TSV (Tab-Separated Values)를 작성하는 function |
write_csv | CSV (Comma-Separated Values) 혹은 TSV (Tab-Separated Values)를 작성하는 function |
read_csv ¶
CSV (Comma-Separated Values) 혹은 TSV (Tab-Separated Values)를 작성하는 function
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | str | 입력될 CSV 혹은 TSV 경로 및 file 이름 | required |
header | bool | Header의 존재 유무 | True |
Returns:
| Type | Description |
|---|---|
dict[int | str, list[str]] | Header의 값을 기반으로 column에 따라 |
Note
Header가 존재하지 않는 경우 0 부터 차례대로 key 값 정의
Examples:
>>> zz.util.read_csv("star_craft.csv")
defaultdict(<class 'list'>, {'id': ['5hi9', 'gor2', 'gk03'], 'Races': ['Protoss', 'Terran', 'Zerg'], 'Scores': ['1248', '2309', '291']})
>>> zz.util.read_csv("star_craft.tsv")
defaultdict(<class 'list'>, {'id': ['5hi9', 'gor2', 'gk03'], 'Races': ['Protoss', 'Terran', 'Zerg'], 'Scores': ['1248', '2309', '291']})
>>> zz.util.read_csv("star_craft.csv", header=False)
defaultdict(<class 'list'>, {0: ['id', '5hi9', 'gor2', 'gk03'], 1: ['Races', 'Protoss', 'Terran', 'Zerg'], 2: ['Scores', '1248', '2309', '291']})
>>> zz.util.read_csv("star_craft.tsv", header=False)
defaultdict(<class 'list'>, {0: ['id', '5hi9', 'gor2', 'gk03'], 1: ['Races', 'Protoss', 'Terran', 'Zerg'], 2: ['Scores', '1248', '2309', '291']})
Source code in zerohertzLib/util/csv.py
write_csv ¶
CSV (Comma-Separated Values) 혹은 TSV (Tab-Separated Values)를 작성하는 function
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | list[list[Any]] | 입력 data (header 포함 무관) | required |
path | str | 출력될 CSV 혹은 TSV 경로 및 file 이름 | required |
tsv | bool | TSV 작성 여부 | False |
Returns:
| Type | Description |
|---|---|
str | File의 절대 경로 |
Examples:
>>> zz.util.write_csv([["id", "Races", "Scores"], ["5hi9", "Protoss", 1248], ["gor2", "Terran", 2309], ["gk03", "Zerg", 291]], "zerohertzLib/star_craft")
'/.../star_craft.csv'
>>> zz.util.write_csv([["id", "Races", "Scores"], ["5hi9", "Protoss", 1248], ["gor2", "Terran", 2309], ["gk03", "Zerg", 291]], "zerohertzLib/star_craft", True)
'/.../star_craft.tsv'