我´我正在尝试实现一个过滤代码:
例如:
import pandas as pd
import operator #this lets you do logical operations
df = pd.read_csv('file.csv')
Filter_column = input('> ') # I will do a filter in this column
comparision = input('> ') # Here goes the logical comparission (==, >, <, etc)
filter_value = input('> ') # Here goes the value to do the filter
if comparision == '=': #Say comparision = '=' in this example
filter_value.astype(type(df['Filter_column)].dropna()[0])) #!!!
filter = operator.eq(df['Filter_column'],filter_value))
dp = df[filter]
然后,dp是给定过滤条件的过滤数据集
在我放置注释的行中,#!!!
是转换输入字符串filter_value
的数据类型的理想方法。熊猫可以使用.astype()
方法更改列值的数据类型。
但这不是字符串的有效方法。有没有办法将输入字符串的数据类型转换为任意给定对象的相同数据类型
目前没有回答
相关问题 更多 >
编程相关推荐