LoginSignup
0
1

More than 3 years have passed since last update.

コンマや△の入った数値を数値型に変換する。

Last updated at Posted at 2020-08-12

1 この記事は

有価証券報報告書に記載されている△や,の入った数値をpythonが扱える数値型に変換するコードを掲載します

2 コード作成例

パターン1

'△45,931'の場合

test.py
moji='△45,931'

def conv(moji):
    moji=moji.replace('△', '-')
    moji=moji.split(' ')[-1]
    moji=moji.replace(',', '') 
    moji=int(moji)
    return moji

moji=conv(moji)
print(type(moji))  ##<class 'int'>
print(moji)        ##-45931

パターン2

'※1 889,341'の場合

test.py
moji='※1 889,341'
def conv(moji):
    moji=moji.replace('△', '-')
    moji=moji.split(' ')[-1]
    moji=moji.replace(',', '') 
    moji=int(moji)
    return moji

moji=conv(moji)
print(type(moji)) #<class 'int'>
print(moji) #889341
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1