简体   繁体   English

Pandas Dataframe 过滤器包含('.'),Python 3.6

[英]Pandas Dataframe Filter contains('.'), Python 3.6

I have Dataframe which contains Year from 1947-2019, but one row contains '2018.1'.我有 Dataframe 包含 1947-2019 的年份,但一行包含“2018.1”。 When I filter for Data where Date contains ".", results gives all the Data当我过滤日期包含“。”的数据时,结果会给出所有数据

DataAll.loc[DataAll['Date'].astype(str).str.contains('.'), 'Date']

I have checked for Data Types and all are in string我已经检查了数据类型并且都在字符串中

DataAll['Date'].apply(type).unique()
array([<class 'str'>], dtype=object)

How to filter Data which contains ".", Please help.如何过滤包含“。”的数据,请帮助。

Here is .这里是. special regex chcaracter, so need regex=False or escape it:特殊的正则表达式字符,所以需要regex=False或转义它:

DataAll.loc[DataAll['Date'].astype(str).str.contains('.', regex=False), 'Date']

DataAll.loc[DataAll['Date'].astype(str).str.contains('\.'), 'Date']

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

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