일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- Button
- ipad
- 삼성소프트웨어멤버십
- Series
- Python
- GitHub
- DFS
- CNN
- GT-S80
- 알고리즘
- mean
- SciPy
- mariadb
- install
- synology
- dataframe
- E-P1
- pandas
- Lotto
- javascript
- pip
- Numpy
- Splunk
- LSTM
- SPL
- imread
- keras
- pycharm
- RNN
- index
Archives
- Today
- Total
잠토의 잠망경
[Pandas] Data 만들기(Series, DataFrame) 본문
Series 만들기
가장 단순한 방식, index 지정 안함
import pandas as pd
s = pd.Series(['a',42])
print(s)
print(type(s))
output
>>> print(s)
0 a
1 42
dtype: object
>>> print(type(s))
<class 'pandas.core.series.Series'>
Series 만들기, index를 지정
import pandas as pd
s = pd.Series(['a',42],index=['name','age'])
print(s)
print(type(s))
output
>>> print(s)
name a
age 42
dtype: object
>>> print(type(s))
<class 'pandas.core.series.Series'>
DataFrame 만들기
import pandas as pd
s = pd.DataFrame({'Name':['a','b'],
'Address':['Seoul','Asan'],
'occupation':['doctor','IT'],
'Born':['1981-01-10','1999-11-02'],
'Died':['2100-01-10','2099-01-02'],
'Age':[40,20]})
print(s)
print(type(s))
output
>>> print(s)
Address Age Born Died Name occupation
0 Seoul 40 1981-01-10 2100-01-10 a doctor
1 Asan 20 1999-11-02 2099-01-02 b IT
>>>
>>> print(type(s))
<class 'pandas.core.frame.DataFrame'>
DataFrame 만들기, index를 지정
columns로 원하는 column의 위치와 숨김 표현을 구현할 수 있다.
index를 통하여 dataFrame의 index로 넣을 수 있다.
import pandas as pd
s = pd.DataFrame({ 'Address':['Seoul','Asan'],
'occupation':['doctor','IT'],
'Born':['1981-01-10','1999-11-02'],
'Died':['2100-01-10','2099-01-02'],
'Age':[40,20]},
index=['a','b'],
columns=['occupation', 'Born', 'Died','Age'])
print(s)
output
>>> print(s)
occupation Born Died Age
a doctor 1981-01-10 2100-01-10 40
b IT 1999-11-02 2099-01-02 20
순서보장 Dictionary를 활용
데이터 입력순서를 그대로 만들어 준다.
import pandas as pd
from collections import OrderedDict
s = pd.DataFrame(
OrderedDict([
('Name',['a','b']),
('Address',['Seoul','Asan']),
('occupation',['doctor','IT']),
('Born',['1981-01-10','1999-11-02']),
('Died',['2100-01-10','2099-01-02']),
('Age',['40','20']),
])
)
print(s)
output
>>> print(s)
Name Address occupation Born Died Age
0 a Seoul doctor 1981-01-10 2100-01-10 40
1 b Asan IT 1999-11-02 2099-01-02 20
Comments