[PYTHON] 8rep --Pandas string delete code

Delete unnecessary characters with 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 to dataframe

#Row unit missing value judgment
df_all.isnull().any(axis=1)

#Removed some NaN lines
df_all=df_all.dropna(how="any")

#Specify delete character
replace_str={
    '@': '',
    '\+': '',
    '\$': '',
    '\|': '',
    '\<': '',
    '\>': '',
    '\-': '',
    '\;': ''
}

#Delete a specific string
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)

Recommended Posts

8rep --Pandas string delete code
9rep --Pandas MySQL
[Pandas] Delete duplicates while complementing defects
Create a pandas Dataframe from a string.
Pandas memo ~ None, np.nan, empty string ~