0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

8rep - Pandas 文字列削除コード

Last updated at Posted at 2020-04-11

Pandasで不要文字削除

from sqlalchemy import create_engine
import pandas as pd

fname="{Pth}.csv"
reader = pd.read_csv(fname, chunksize=1000, sep='\t',low_memory = False)
df_all = reader.get_chunk() # chunkをdataframe

# 行単位欠損値判定
df_all.isnull().any(axis=1)

# 一部がNaNな行を削除
df_all=df_all.dropna(how="any")

# 削除文字指定
replace_str={
    '@': '',
    '\+': '',
    '\$': '',
    '\|': '',
    '\<': '',
    '\>': '',
    '\-': '',
    '\;': ''
}

# 特定の文字列削除
df_all["comment"]=df_all["comment"].replace(replace_str, regex=True, encoding='utf-8')

print(df_all)
df_all.to_csv('{Pth}/replace.csv', sep='\t', index=False)
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?