PyPackage01---Pandas14_对类别型变量做映射_pandas 映射为类别数字-CSDN博客

网站介绍:文章浏览阅读275次。Intro有时候,需要把字符串当做代码执行,看个例子getattrGet a named attribute from an object; getattr(x, ‘y’) is equivalent to x.yimport pandas as pddf=pd.DataFrame({"x":[1,2,3]})getattr(df,"x").count()3getattr(df,“x”)相当于df.x如果想执行df.x*2怎么弄?evaleval("df.x*2")0 _pandas 映射为类别数字