The str.replace function throws an error that an integer is required

I want to ask the problem I am facing. First let me show you all my code

df1 = pd.read_excel(r'E:\내논문자료\골목상권 데이터\이태원로 54길 내용뺀거.xlsx' , sheetname='first_day_datas')
df1.registerdate= df1.registerdate.astype(str) # 칼럼 속성 바꾸기
df2 = pd.to_datetime(df1['registerdate'].str[0:10])
df3 = df2['registerdate'].str.replace('-', '').str.strip()

I just want to change the row in the registerdate column. when I put the seal (df2.head (3)). It shows as below

0   2016-10-11
1   2016-10-15
2   2016-10-15

so I want to replace "-" with "". I type in the code and get "TypeError: integer required".

+4
source share
2 answers
df2 = pd.to_datetime(df1['registerdate'].str[0:10])
#     \____________/
#    returns a series

df2['registerdate'].str.replace('-', '').str.strip()
#\_______________/
# is only something
# if 'registration
# is in the index
# this is probably the source of your error

At this moment df2there is pd.Seriesof Timestamps. format yyyy-mm-ddis a way to display Timestamp. To display it as yyyymmdddo it

df2.dt.strftime('%Y%m%d')

0    20160331
1    20160401
2    20160402
3    20160403
4    20160404
Name: registerdate, dtype: object
+1
source

, df2 'registerdate', . , df2.map(lambda x: x.strftime('%Y%m%d') .

+1

Source: https://habr.com/ru/post/1658152/


All Articles