일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- keras
- Numpy
- mariadb
- javascript
- imread
- Series
- install
- pandas
- Python
- Splunk
- GT-S80
- index
- SciPy
- Button
- GitHub
- SPL
- Lotto
- RNN
- pip
- E-P1
- ipad
- DFS
- CNN
- dataframe
- mean
- 알고리즘
- LSTM
- 삼성소프트웨어멤버십
- pycharm
- synology
Archives
- Today
- Total
잠토의 잠망경
[pandas] AttributeError: 'Timestamp' object has no attribute 'translate' 본문
공부/Python
[pandas] AttributeError: 'Timestamp' object has no attribute 'translate'
잠수함토끼 2020. 5. 23. 08:46mariadb를 사용하다 보면 timestamp 오류가 발생할 경우가 있다.
AttributeError: 'Timestamp' object has no attribute 'translate'
해당 오류가 발생할 경우 해결책
datas = pd.DataFrame({'col1': [' ab_c', 'b: cd', 'cde_ '],
'col2': ['a', 'a', 'c'],
'col3': [1, 2, 3],
'mydate': [pd.to_datetime('20200402'),
pd.to_datetime('20200501')-pd.DateOffset(days=5),
pd.to_datetime('20200502')]
},
index=[0, 1, 2])
print(datas.info())
다음과 datetime64[ns]가 나온다.
Data columns (total 4 columns):
col1 3 non-null object
col2 3 non-null object
col3 3 non-null int64
mydate 3 non-null datetime64[ns]
dtypes: datetime64[ns](1), int64(1), object(2)
memory usage: 120.0+ bytes
None
해결 방식 : astype(str)를 사용하여 형변환 진행함
astype(str)를 사용하여 형변환 진행함
이걸 object 형태로 변경해야 정상적으로 동작한다.
datas['mydate_str'] = datas['mydate'].astype(str) # 문자열 형식으로 변환
print(datas.info())
<class 'pandas.core.frame.DataFrame'>
Int64Index: 3 entries, 0 to 2
Data columns (total 5 columns):
col1 3 non-null object
col2 3 non-null object
col3 3 non-null int64
mydate 3 non-null datetime64[ns]
mydate_str 3 non-null object
dtypes: datetime64[ns](1), int64(1), object(3)
memory usage: 144.0+ bytes
None
Process finished with exit code 0
※ 참조
Comments