본문 바로가기
728x90
반응형

Python286

[Python] Unicode and Python : Unicode Literal 0. 시작하기 전 참고 URLsLiteral에 대한 자료.https://dsaint31.tistory.com/462 [Basic] LiteralLiteral소스 코드 상에서 고정된 값을 가르킴. (또는 고정된 값을 나타내는 표기법을 의미함.)Programming language에서 data의 값을 지정(specifying data values)하는 방법은 다음 중의 하나임.1. Literal을 사용.2dsaint31.tistory.com Unicode에 대한 자료.https://dsaint31.me/mkdocs_site/CE/ch01/code_for_character/#unicode BME228Codes for Characters Code 란 특정 형태의 information을 다른 방법으로 표현하는 규.. 2024. 1. 16.
[Python] Binary Bitwise Operations Python의 binary bitwise operoator는 다음과 같음. 표에서 binary result부분은 다음과 같은 x, y 에서의 결과임.x : 0b0101 ( = 5 )y : 0b0001 ( = 1)OperatorDescriptionExampleDecimal resultBinary result&Andx & y10b0001|Orx | y50b0101^Exclusive Orx ^ y40b0100~Flip bits~x-6binary representation depends on int sizeLeft shiftx 100b1010>>Right shiftx >> 120b0010 Note : Flip bits (not 연산)https://dsaint31.me/mkdocs_site/CE/ch01/nega.. 2024. 1. 15.
[Python] `struct` 사용하기: bytes 로 C언어 구조체 다루기. struct 모듈binary data를 보다 쉽게 파싱해주는 기능을 제공한다. C언어의 구조체로 명시된 binary data를 네트워크 등으로 받은 경우나,binary format으로 특정 header정보를 가지고 있는 파일들을 읽어들일 때,특정 바이트 크기에 할당된 변수 값들을 Python의 변수들에 제대로 할당하는데 많이 사용된다.주요함수크게 다음 3가지의 함수를 이용한다.packC 언어의 구조체 등으로 읽어들일 수 있는 binary data에 해당하는 bytes객체를 만들어내는 함수.현재 python의 변수들의 값들을 지정된 format의 binary data에 해당하는 bytes객체로 변경한다.bytes_v = struct.pack(format, variable0, variable1, ...)Py.. 2024. 1. 15.
[Python] bytes and bytearray: Binary Data for Python Python에서 bytes와 bytearray는binary data를 byte 단위 (1byte = 8bit)로 다루는데사용되는 Data Type임.bytes:bytes 는 immutable byte sequence 로서 일종의 byte로 구성된 tuple에 해당 함.byte literal은 다음과 같이 b라는 prefix를 사용함.b'Hello'은 'Hello'라는 문자열에 대한 byte literal을 의미함.문자열에 대한 bytes 이므로 encoding이 사용되며 기본으로 utf8이 사용됨.byte literal과 같이 추후 변경이 되지 않는 binary data를 위한 데이터 타입이 bytes임.bytes 객체를 출력할 경우,utf8인 경우에는 ascii에 해당하는 바이트는 ascii 문자로 출.. 2024. 1. 15.
[python] Text mode vs. Binary mode: File open Python에서 특정 파일을 open하는 경우, text mode 또는 binary mode 중 하나로 열게 된다.기본은 text mode임. 이 둘의 차이점은 간단히 설명하면,현재 open하고자 하는 file을 text파일로 처리할지아니면 binary파일로 처리할지를 결정하는 것임.1. binary mode 로 file을 여는 경우,Python은 해당 file을 순수한 bytes의 형태로 취급함: bytes, bytearray 로 처리해당 파일을 byte 단위로 읽어들이면서어떠한 변환없이 file에 기재된 bytes 의 값들을 그대로 읽어들임.2. text mode로 file을 여는 경우,사람이 읽을 수 있는 문자들로 구성된 text file이라고 생각: str 로 처리file의 bytes 값들을 사.. 2024. 1. 15.
[pandas] 데이터 타입에 따른 column 추출: select_dtypes() DataFrame의 경우, dtypes attribute를 통해 각 column의 data type을 가지고 있음. (Series 형임)DataFrame객체들을 서로 빼주는 등의 연산을 할 때, numberic type이 아닌 column이 있을 경우 문제가 발생함.때문에 numberic type으로 구성된 columns를 추출해야 하는 경우가 있음.다음의 코드를 참고할 것.import pandas as pddf = pd.DataFrame( { "test_id" : [ 0, 1, 2, 3, 4, 5], "test_int": [ 10, 20, 30, 40, 50, 60], "test_obj0": [ "a", "b", "c", "d", "e", "f"], .. 2024. 1. 12.
728x90
반응형