작성
·
270
답변 2
1
1
안녕하세요.
{"a":[4, 5, 6]} 으로 딕셔너리 형태의 데이터를 데이터프레임으로 변환해 주면 키값이 컬럼이 됩니다.
[[4, 5, 6]] 으로 된 2차원 행렬값을 데이터프레임으로 변환해 주면 리스트 하나가 하나의 행이 됩니다.
그래서 아래와 같이 데이터프레임을 생성해 주면 각 리스트가 행의 Series 형태로 들어가게 됩니다.
pd.DataFrame([[1,2,3],
[4,5,6],
[7,8,9]])
딕셔너리인지 2차원 행렬인지에 따라 생성되는 구조가 달라지게 됩니다.
아래의 내용은 데이터프렘 문서인데 질문 주신 내용에 대한 예제가 있어서 함께 참고해 보세요.
Examples -------- Constructing DataFrame from a dictionary. >>> d = {'col1': [1, 2], 'col2': [3, 4]} >>> df = pd.DataFrame(data=d) >>> df col1 col2 0 1 3 1 2 4 Notice that the inferred dtype is int64. >>> df.dtypes col1 int64 col2 int64 dtype: object To enforce a single dtype: >>> df = pd.DataFrame(data=d, dtype=np.int8) >>> df.dtypes col1 int8 col2 int8 dtype: object Constructing DataFrame from numpy ndarray: >>> df2 = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), ... columns=['a', 'b', 'c']) >>> df2 a b c 0 1 2 3 1 4 5 6 2 7 8 9