美文网首页
python 虚拟变量

python 虚拟变量

作者: 正在充电Loading | 来源:发表于2017-08-28 00:26 被阅读0次

# -*- coding: utf-8 -*-

import pandas

data = pandas.read_csv(

'D:\\PDA\\4.18\\data.csv',

encoding='utf8'

)

data['Education Level'].drop_duplicates()

"""

博士后    Post-Doc

博士      Doctorate

硕士      Master's Degree

学士      Bachelor's Degree

副学士    Associate's Degree

专业院校  Some College

职业学校  Trade School

高中      High School

小学      Grade School

"""

educationLevelDict = {

'Post-Doc': 9,

'Doctorate': 8,

'Master\'s Degree': 7,

'Bachelor\'s Degree': 6,

'Associate\'s Degree': 5,

'Some College': 4,

'Trade School': 3,

'High School': 2,

'Grade School': 1

}

data['Education Level Map'] = data[

'Education Level'

].map(

educationLevelDict

)

data['Gender'].drop_duplicates()

dummies = pandas.get_dummies(

data,

columns=['Gender'],

prefix=['Gender'],

prefix_sep="_",

dummy_na=False,

drop_first=False

)

dummies['Gender'] = data['Gender']

相关文章

  • python 虚拟变量

    # -*- coding: utf-8 -*- import pandas data = pandas.read_...

  • 如何使用Pandas的get_dummies在Python中创建

    在本文中,我们将学习如何使用Pandas的 get_dummies()方法在Python中创建虚拟变量。 虚拟变量...

  • pyvenv,virtualenv, pyenv,pyenv-v

    虚拟环境的工作原理 主要就是操作环境变量。Python在非虚拟环境下的路径:$which python/usr/b...

  • Pycharm

    1. 删除Pycharm虚拟环境。 2.添加anaconda python的环境变量 vi ~/.bash_pro...

  • 哑变量/虚拟变量

    什么是虚拟变量(哑变量)? 虚拟变量又称哑变量,是人为设定的用于将分类变量引入回归模型中的方法。 为什么要使用虚拟...

  • 数据分析中的哑变量问题,该怎么处理?

    什么是虚拟变量? 虚拟变量又称哑变量,是人为设定的用于将分类变量引入模型中的方法。 为什么要使用虚拟变量 在回归分...

  • 虚拟变量

    虚拟变量 ( Dummy Variables) 又称虚设变量、名义变量或哑变量,用以反映质的属性的一个人工变量,是...

  • Centenos虚拟环境

    进入虚拟环境: python 3.6.2 搭建python的虚拟环境 python -m venv /myblog...

  • Python学习笔记-3群18组-杜杜狼-2017.7.24

    Lesson 26 虚拟变量 虚拟变量又叫哑变量和离散特征编码,用来表示分类变量,非数量因素可能产生的影响 离散特...

  • 1.1 python变量/输出/输入

    python版本:python 3.5.2注释符号:#发布时间:2018.10.26 一、变量 变量是什么? 变量...

网友评论

      本文标题:python 虚拟变量

      本文链接:https://www.haomeiwen.com/subject/azfwdxtx.html