일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 프로그래머스
- JSON
- error
- SSH
- Numpy
- 기타 연주
- windows forms
- Visual Studio
- pandas
- nvidia-smi
- pip
- OpenCV
- VS Code
- C#
- pytorch
- YOLO
- 오류
- 핑거스타일
- label
- 채보
- Selenium
- C
- ubuntu
- Docker
- Linux
- Python
- mysql
- paramiko
- 컨테이너
- C++
- Today
- Total
목록Python (117)
기계는 거짓말하지 않는다

import pandas as pd df = pd.read_csv("custom_data.csv", encoding="utf-8") # & (and), | (or) print(df[(df["count"] >= 200) & (df["price"] >= 1000)]) # ~ (not) print(df[~(df["price"] >= 500) | ~(df["count"] > 10)]) ''' query를 이용하여 다중 조건을 한 번에 처리할 수 있다. Column에 ` (Backtick)을 사용하는 이유는 Column의 문자열에 특수문자, 띄어쓰기가 포함될 경우 오류가 발생하기 때문이다. ''' query_string = "`count` >= 200 & `price` >= 1000" print(df.query(..

import pandas as pd df = pd.read_csv("custom_data.csv", encoding="utf-8") print(df[df["price"] == 500]) # price의 값이 500 # price의 값이 500 또는 100 print(df[df["price"].isin([500, 100])]) # 조건 print(df[(df["price"] == 500) | (df["price"] == 100)])

Python 3.7 버전부터 기본 Dict도 삽입 순서를 보장한다. 명시적으로는 collections 모듈의 OrderedDict를 사용할 수 있다. Python Ordered Dict 문서 collections — Container datatypes Source code: Lib/collections/__init__.py This module implements specialized container datatypes providing alternatives to Python’s general purpose built-in containers, dict, list, set, and tuple.,,... docs.python.org 아래와 같이 사용할 수 있다. from collections import..
입력받거나 작성된 경로가 절대 경로인지 확인하고 상대 경로이면 절대 경로로, 절대 경로이면 상대 경로로 변환한다. import os data_path = "../../Temp/aa.txt" if not os.path.isabs(data_path): # 절대 경로 변환 data_path = os.path.abspath(data_path) print("abs path:", data_path) else: # 상대 경로 변환 data_path = os.path.relpath(data_path) print("relative path:", data_path)
Python에서 추상클래스를 생성하는 방법이다. abc 모듈이 필요하고 추상클래스의 추상메소드가 존재할 때, 객체를 생성하면 예외가 발생한다. 추상클래스를 상속받은 하위 클래스는 추상메소드를 구현하지 않으면 예외가 발생한다. from abc import * class TempAbstractClass(metaclass=ABCMeta): @abstractmethod def show_val(self): pass class TempClass(TempAbstractClass): def __init__(self, n: int, s: str): self.number = n self.string = s def show_val(self): print(f"Values: {self.number}, {self.string}"..
cv2를 이용할 때 imread, imwrite 한글(utf-8) 인식 문제가 있다. imread, imwrite 함수를 아래와 같이 선언하고 사용한다. import os import cv2 import numpy as np def imread(file_path): npArr = np.fromfile(file_path, dtype=np.uint8) return cv2.imdecode(npArr, cv2.IMREAD_COLOR) def imwrite(file_path, img, params=None): try: ext = os.path.splitext(file_path)[1] result, n = cv2.imencode(ext, img, params) if result: with open(file_path..

문자열은 immutable이므로 문자 수정이 불가능하다. List 변경 후 다시 문자열로 변환하는 방법이 있다. temp_str = "ABCDEF" temp_str = list(temp_str) temp_str[0] = "g" temp_str[1] = "h" temp_str = "".join(temp_str) print(f"Change String: {temp_str} (Type: {type(temp_str)})")
디렉터리 내의 파일들의 경로를 텍스트 파일로 저장한다. 특정 확장자만 제한하려면 argparser로 넘겨준다. argparser 명령어 예시 image_files 디렉터리 내의 png, jpg, jpeg 확장자를 가진 파일들의 경로를 file_list.txt 텍스트 파일로 저장 python file_path_list_to_text.py -p ./image_files -t file_list.txt -e png jpg jpeg import glob import argparse import os def parse_opt(): parser = argparse.ArgumentParser() parser.add_argument('-p', '--path', default=".", help="data path") pa..