栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python:pandas学习笔记

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python:pandas学习笔记

import pandas

sub_info = pandas.read_csv("contract.csv")

#sub_info

#print (sub_info)

type(sub_info)

#print (sub_info.dtypes)


first_rows = sub_info.head(1)

#print (first_rows)

#print (sub_info.columns)

#print (sub_info.shape)

#print (sub_info.loc[1])

sub_info.loc[0:3]


two_five_nine = [2,5,9]

sub_info.loc[two_five_nine]


id1 = sub_info["CONTRACTID"]

id1


str1 = ["CONTRACTID","STATUS"]

id2 = sub_info[str1]

id2


sub_info.columns

columns_list = sub_info.columns.tolist()


time_list = []

for i in columns_list:

    if i.endswith("TIME"):

        time_list.append(i)


time_info = sub_info[time_list]


is_value_empty = time_info.isnull()

is_value_empty

time_info.fillna("0")


#用前一个数据代替NaN:method='pad'

time_info.fillna(method='pad')

#与pad相反,bfill表示用后一个数据代替NaN

time_info.fillna(method='bfill')

#用limit限制每列可以替代NaN的数目

time_info.fillna(method='bfill',limit=1)

#使用平均数代替NaN

time_info.fillna(time_info.mean())

#指定列 数据代替NaN

time_info.fillna(time_info.mean()['SUBTIME':'OPRTIME'])

test_info = sub_info[["CONTRACTID","STATUS"]]


#A value is trying to be set on a copy of a slice from a Dataframe

test_num = test_info["STATUS"] / 10

test_info["test"] = test_num

test_info


test_num = sub_info["STATUS"] / 10

sub_info["test"] = test_num

sub_info


CONTRACTID_MAX = sub_info["CONTRACTID"].max()

max_percent = sub_info["CONTRACTID"] / CONTRACTID_MAX

sub_info["max_percent"] = max_percent


#对列排序,参数True 表示不产生拷贝,直接在原矩阵操作 

sub_info.sort_values("CONTRACTID",inplace=True)

sub_info

#ascending 降序

sub_info.sort_values("CONTRACTID",inplace=True,ascending=False)

sub_info


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/224930.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号