판다스 컬럼을 열로 변환하는 방법
판다스 컬럼을 열로 변환하는 방법¶ In [1]: import pandas as pd # 예시 데이터프레임 생성 df = pd.DataFrame({ 'A': ['jin', 'Lee', 'Yuri'], 'B': ['apple', 'banana', 'orange'], 'C': [1.1, 2.1, 3.1], 'D': [40, 50, 60] }) df Out[1]: A B C D 0 jin apple 1.1 40 1 Lee banana 2.1 50 2 Yuri orange 3.1 60 In [2]: # 'melt' 함수를 사용하여 컬럼을 열로 변환 melt..
2023. 5. 22.
pytorch tensor.new, 파이토치 tensor.new new_zeros(), new_ones(), new_full()
pytorch tensor.new, 파이토치 tensor.new new_zeros(), new_ones(), new_full() 설명 tensor.new()는 PyTorch에서 주어진 tensor의 속성(데이터 타입, 디바이스 등)을 그대로 유지하면서 새로운 tensor를 생성하는 데 사용되는 메서드입니다. new() 사용예시 import torch # 기존 tensor 생성 original_tensor = torch.tensor([[1, 2], [3, 4]], dtype=torch.float32, device='cpu') # new()를 사용하여 기존 tensor와 동일한 속성을 가진 새로운 tensor 생성 new_tensor = original_tensor.new(2, 2) print(new_ten..
2023. 5. 18.
파이썬 리스트를 tsv 로 저장
파이썬 리스트를 tsv 로 저장 예시 리스트 만들기 # (질문, 대답) 형태로 예시 리스트를 생성합니다. QA = [ ("What is the primary function of the heart?", "To pump blood through the circulatory system."), ("Where is the Great Barrier Reef situated?", "Off the coast of Queensland, Australia"), ("What is the Sun mainly composed of?", "Hot plasma"), ("Who designed the Eiffel Tower?", "Gustave Eiffel"), ("Will there be a London Marathon in ..
2023. 5. 10.