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 |
Tags
- AWS
- pytorch
- C++
- STL
- 구현
- 자료구조 및 실습
- 백준
- MySQL
- 1단계
- 실전알고리즘
- 머신러닝
- 그리디
- SWEA
- Python
- 3단계
- 딥러닝
- 프로그래머스
- 전산기초
- 코드수행
- 2단계
- test-helper
- cs
- 모두를 위한 딥러닝 강좌 시즌1
- ssd
- docker
- ubuntu
- CS231n
- 이것이 코딩테스트다 with 파이썬
- 파이썬
- Object detection
Archives
- Today
- Total
곰퓨타의 SW 이야기
[python] pandas로 labeling type 수정하여 txt 파일 저장하기 본문
python에서 numpy를 통해 열 마다 다른 type으로 저장하고자 하였으나, 실패하였다.
따라서 pandas의 DataFrame을 활용하여 열마다 다른 type으로 저장하는 방법을 고안하였다.
import pandas as pd
import numpy as np
annot = np.loadtxt('/path_txt_file.txt',delimiter=',',skiprows=0,dtype= float)
# 1열은 1로 채우고자 하는 경우
annot[:,1] = np.ones(len(annot),dtype=int)
df = pd.DataFrame(annot)
# 2,3,4,5 열은 float 형으로 놔두지만, 다른 열들은 int로 형변환하고자 하는 경우
df[0] = df[0].astype(int)
df[1] = df[1].astype(int)
df[6]= df[6].astype(int)
df[7]= df[7].astype(int)
df[8]= df[8].astype(int)
df[9]= df[9].astype(int)
print(df)
# index 는 말그대로 index, header는 column 제외하고 저장하고 싶은 경우
df.to_csv('label_remove.txt',sep=',', index =False, header=False)
'Project > python 활용(ex.openCV)' 카테고리의 다른 글
[face detection] opencv, dlib, mtcnn (0) | 2021.05.12 |
---|---|
[python] detectron2의 demo.py를 변환하여 txt 파일로 저장하기 (0) | 2021.05.10 |
[python] image size 아는 법 (0) | 2021.04.21 |
[python] opencv video to image (0) | 2021.04.21 |
[python] ffmpeg를 활용하여 image to video 수행하기 (0) | 2021.04.21 |
Comments