寻找带字母的数字

2024-04-19 17:17:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我想选择一个DataFrame列,遍历它,只选择数字,并用“Unknow”替换包含字母和其他符号的数字。我尝试了isreal()方法,但没有成功。有没有办法不用函数就完成这个任务?你知道吗

%matplotlib inline
%pylab inline
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
file = 'C:/Users/Сынкетру/Desktop/attacks.csv'
df = pd.read_csv(file, sep=',', encoding='ISO-8859-1') 


df_clean = df.Age.dropna()

def age(number):
    try:
        number = df.isreal()
    except ValueError:
        number = 'Unknown'

map(age, df_clean)
print(d)

Tags: csvimportcleannumberdataframedfagematplotlib