Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Actor-Critic
- remove outliers
- MRI
- Policy Gradient
- loss functions
- sidleup
- normalization
- non parametic softmax
- objective functions for machine learning
- Excel
- pulloff
- domain adaptation
- sample rows
- freebooze
- thresholding
- 3d medical image
- resample
- Inorder Traversal
- fastapi
- scowl
- clip intensity values
- checkitout
- REINFORCE
- Knowledge Distillation
- 자료구조
- rest-api
- noise contrast estimation
- straightup
- model-free control
- shadowing
Archives
- Today
- Total
Let's Run Jinyeah
[Python] Read/Write csv file (csv, Pandas) 본문
What is difference between csv(.csv) and excel(.xls)?
1. CSV
- simple type of plain text file which uses a specific structure to arrange tabular data
- a newline terminates each row to begin the next row
- each column is separated by a comman within a row
2. Excel
- spreadsheet software included in the Microsoft office suite
- binary file that holds information about all the worksheets in a workbook
Read & Write csv file
[csv]
- built-in module
- doesn't provide scientific data manipulation tools that Pandas does
- write
- use write() : Each line should be separated by "\n"
- write(): wirte a single string
- writelines(): write a sequence of strings(tuple, list)
- use csv.write()
- wirterow(): write data into the file as a line
- writerows()
- use write() : Each line should be separated by "\n"
import csv
# write
info_list = [ ['Nikhil', 'COE', '2', '9.0'],
['Sanchit', 'COE', '2', '9.1'],
['Aditya', 'IT', '2', '9.3'],
['Sagar', 'SE', '1', '9.5'],
['Prateek', 'MCE', '3', '7.8'],
['Sahil', 'EP', '2', '9.1']]
output_dir = "./<result_file>.csv"
with open(output_dir, 'w') as csvfile:
# use csv.writer()
csvwriter = csv.writer(csvfile)
csvwriter.writerows(info_list)
# use wirte()
for a in info_list:
file.writelines(f"{a}\n") # file.writerow(f"{a})
- read
dataset_file = "./<csv_file>.csv"
with open(dataset_file) as csv_file:
# delimiter: character that separates text in a line
csv_reader = csv.reader(csv_file, delimiter=",")
list_of_rows = list(csv_reader)
for row in list_of_rows:
print(row)
"""
output:
['Nikhil', 'COE', '2', '9.0']
['Sanchit', 'COE', '2', '9.1']
['Aditya', 'IT', '2', '9.3']
['Sagar', 'SE', '1', '9.5']
['Prateek', 'MCE', '3', '7.8']
['Sahil', 'EP', '2', '9.1']
"""
[pandas]
- library that should be manually installed
- changes csv file to dataframe needed for manipulating data with pandas
- provide various scientific data manipulation tools
< Summary >
In data-warehouse, Excel is preferable for detailed standardized schema specification
If you want only reading csv file, use csv (pandas will increase dependencies of project)
if you handle a big data and need various data manipulation, use pandas
reference
https://www.guru99.com/excel-vs-csv.html
https://www.delftstack.com/ko/howto/python/how-to-read-csv-to-list-in-python/
'Programming > Python' 카테고리의 다른 글
[Window] Python 설정 (0) | 2022.10.24 |
---|---|
Numpy 모음 (0) | 2022.06.17 |
[Python] Modify DICOM image and save as DICOM (0) | 2022.05.19 |
[Python] 가상환경 생성 및 활성화 (0) | 2022.05.17 |
[Python] List method (0) | 2021.10.19 |
Comments