김지영
김지영

Reputation: 359

How to drop the row?

I'm handling my data now.

I got a problems when I using pandas

Here is the code.

import pandas as pd
import numpy as np
import os

join_file2 = r'D:\raw data\서울시 공공데이터\5.16년7월분\17.상권-추정매출\tbsm_trdar_selng.txt\tbsm_trdar_selng_utf8.txt'
os.chdir(os.path.dirname(join_file2))
join_data2 = pd.read_csv(os.path.basename(join_file2),sep='|',
                header=None ,
                usecols=[0,1,2,3,4,11],
                names=['STDR_YM_CD', 'TRDAR_CD', 'TRDAR_CD_NM', 'SVC_INDUTY_CD','SVC_INDUTY_CD_NM','THSMON_SELNG_AMT'],
                dtype = { '0' : int},
                encoding='utf-8' )

join_data2_d = join_data2[(join_data2.SVC_INDUTY_CD != 'CS000000') | (join_data2.SVC_INDUTY_CD != 'CS100000') | (join_data2.SVC_INDUTY_CD != 'CS200000')| (join_data2.SVC_INDUTY_CD != 'CS300000') ]

When I print join_data2.head(), I got this data enter image description here

and print join_data2_d, I got this which doesn't drop rows. enter image description here

How can I fix it?? Here is my data link. http://blogattach.naver.com/f96ce5504c7273c4e30c6a5e6581fe8323768bd1/20170214_57_blogfile/khm2963_1487051333659_hYIWuM_zip/tbsm_trdar_selng_utf8.zip?type=attachment

Upvotes: 0

Views: 61

Answers (1)

Ted Petrou
Ted Petrou

Reputation: 62007

It appears that you are trying to filter out rows that have SVC_INDUTY_CD not equal to several values. You should use the isin method and reverse it using the unary operator ~

join_data2_d = join_data2[~join_data2.SVC_INDUTY_CD.isin(['CS000000',
                                                          'CS100000',
                                                          'CS200000',
                                                          'CS300000'])]

Upvotes: 1

Related Questions