首页 > 编程 > Python > 正文

对Python中DataFrame选择某列值为XX的行实例详解

2019-11-25 13:21:55
字体:
来源:转载
供稿:网友

如下所示:

#-*-coding:utf8-*-import pandas as pd  all_data=pd.read_csv("E:/协和问答系统/SenLiu/熵测试数据.csv")#获取某一列值为xx的行的候选列数据print(all_data)feature_data=all_data.iloc[:,[0,-1]][all_data[all_data.T.index[0]]=='青年']print(feature_data)

实验结果如下:

"C:/Program Files/Anaconda3/python.exe" D:/pycharmprogram/learn/pandas_learn/learn_test.py  年龄 有工作 有自己的房子 信贷情况 类别0  青年  否   否  一般 否1  青年  否   否  好 否2  青年  是   否  好 是3  青年  是   是  一般 是4  青年  否   否  一般 否5  中年  否   否  一般 否6  中年  否   否  好 否7  中年  是   是  好 是8  中年  否   是 非常好 是9  中年  否   是 非常好 是10 老年  否   是 非常好 是11 老年  否   是  好 是12 老年  是   否  好 是13 老年  是   否 非常好 是14 老年  否   否  一般 否  年龄 类别0 青年 否1 青年 否2 青年 是3 青年 是4 青年 否 Process finished with exit code 0

以上这篇对Python中DataFrame选择某列值为XX的行实例详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持武林网。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表