728x90
Creating DataFrames¶
In [1]:
import pandas as pd
In [2]:
df = pd.DataFrame(
{"a" : [4,5,6],
"b" : [7,8,9],
"c" : [10,11,12]}, index = [1,2,3])
In [3]:
df
Out[3]:
a | b | c | |
---|---|---|---|
1 | 4 | 7 | 10 |
2 | 5 | 8 | 11 |
3 | 6 | 9 | 12 |
In [6]:
df = pd.DataFrame(
[[4, 7, 10],
[5, 8, 11],
[6, 9, 12]],
index=[1, 2, 3],
columns=['a', 'b', 'c'])
In [7]:
df
Out[7]:
a | b | c | |
---|---|---|---|
1 | 4 | 7 | 10 |
2 | 5 | 8 | 11 |
3 | 6 | 9 | 12 |
In [8]:
df = pd.DataFrame(
{"a" : [4 ,5, 6],
"b" : [7, 8, 9],
"c" : [10, 11, 12]},
index = pd.MultiIndex.from_tuples(
[('d',1),('d',2),('e',2)],
names=['n','v']))
- pd.MultiIndex.from_tuples: 멀티 인덱스를 생성해줍니다.
In [9]:
df
Out[9]:
a | b | c | ||
---|---|---|---|---|
n | v | |||
d | 1 | 4 | 7 | 10 |
2 | 5 | 8 | 11 | |
e | 2 | 6 | 9 | 12 |
'Python' 카테고리의 다른 글
[Pandas] Pandas Cheat Sheet(Subset Observations(Rows)) (0) | 2021.05.23 |
---|---|
[Pandas] Pandas Cheat Sheet(Reshaping Data) (0) | 2021.05.20 |
[Pandas] Pandas Cheat Sheet (판다스 치트 시트) (1) | 2021.05.16 |
[Pandas] 유일한 값 찾기 unique(), nunique(), value_counts() (4) | 2021.02.02 |
[Python] 결측치/결측값 확인 missingno (0) | 2021.01.25 |