繁体   English   中英

Pandas:需要删除包含字符串的行。 但是我的情况不起作用

[英]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

我有一个文件 CSV 包含 40300 个数据。

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

在这个区域,我正在删除被忽略的行和列

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

在这个区域,如果字符串数据类型面临但它不起作用,我想删除该行

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()

您必须在 df 中重新分配 df 的值

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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