简体   繁体   中英

Pandas: need to remove the row that contains a string. BUT my condition is not working

from chainer import datasets
from chainer.datasets import tuple_dataset
import numpy as np
import matplotlib.pyplot as plt
import chainer
import pandas as pd 
import math

I have a file CSV contains 40300 data.

df =pd.read_csv("Myfile.csv", header = None)

in this area i am removing the ignored rows and columns

columns = [0,1]
rows = [0,1,2]
df.drop(columns, axis = 1, inplace = True) #drop the two first columns that no need to the code
df.drop(rows,  axis = 0, inplace = True) #drop the two first rwos that no need to the code

in this area i want to remove the row if string data type faced BUT its not working

df[~df.E.str.contains("Intf Shut")]~this part is not working with me 

df.to_csv('summary.csv', index = False, header = False)

df.head()

You have to reassign the value of df in df

df = df[~df.E.str.contains("Intf Shut")]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM