hdf5文件、tqdm模块、nunique、read_csv、sort_values、astype、fillna
pandas.DataFrame.to_hdf(self, path_or_buf, key, **kwargs):
Hierarchical Data Format (HDF) ,to add another DataFrame or Series to an existing HDF file, please use append mode and a different a key.
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}, index=['a', 'b', 'c'])
df.to_hdf('data.h5', key='df', mode='w', format='table')
# format : {‘fixed’, ‘table’}, default ‘fixed’
# ‘fixed’: Fixed format. Fast writing/reading. Not-appendable, nor searchable
# ‘table’: Table format. Write as a PyTables Table structure which may perform worse but allow more flexible operations like searching / selecting subsets of the data
s = pd.Series([1, 2, 3, 4])
s.to_hdf('data.h5', key='s')
pd.read_hdf('data.h5', 'df')
pd.read_hdf('data.h5', 's')
tqdm模块显示进度条:
tqdm(self, iterable=None, desc=None, total=None, leave=True, file=None, ncols=None, mininterval=0.1, maxinterval=10.0, miniters=None, ascii=None, disable=False, unit='it', unit_scale=False, dynamic_ncols=False, smoothing=0.3, bar_format=None, initial=0, position=None, postfix=None, unit_divisor=1000, write_bytes=None, gui=False, **kwargs)
iterable : iterable, optional
total : int, optional. The number of expected iterations. If unspecified, len(iterable) is used if possible.
for x in tqdm(train_df['request_timestamp'].values,total=len(train_df)):
localtime=time.localtime(x)
wday.append(localtime[6])
hour.append(localtime[3])
https://lorexxar.cn/2016/07/21/python-tqdm/
https://tqdm.github.io/docs/tqdm/
pandas.DataFrame.nunique:https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.nunique.html
DataFrame.nunique(self, axis=0, dropna=True)
Count distinct observations over requested axis. Return Series with number of distinct observations. Can ignore NaN values.
>>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [1, 1, 1]})
>>> df
A B
0 1 1
1 2 1
2 3 1
>>> df.nunique()
A 3
B 1
dtype: int64
>>> df.nunique(axis=1)
0 1
1 2
2 2
dtype: int64
pandas.read_csv(...)常见参数:
sep : str, default ‘,’
header : int, list of int, default ‘infer’. Row number(s) to use as the column names, and the start of the data. Default behavior is to infer the column names: if no names are passed the behavior is identical to header=0 and column names are inferred from the first line of the file, if column names are passed explicitly then the behavior is identical to header=None.
names : array-like, optional. List of column names to use. Duplicates in this list are not allowed.
df=pd.read_csv('data/testA/totalExposureLog.out', sep='\t',names=['id','request_timestamp','position','uid','aid','imp_ad_size','bid','pctr','quality_ecpm','totalEcpm'])
DataFrame.sort_values(self, by, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last')
# axis这个参数的默认值为0,匹配的是index,跨行进行排序,当axis=1时,匹配的是columns,跨列进行排序
# by这个参数要求传入一个字符或者是一个字符列表,用来指定按照axis的中的哪个元素来进行排序
# ascending这个参数的默认值是True,按照升序排序,当传入False时,按照降序进行排列
# kind这个参数表示按照什么样算法来进行排序,默认值是quicksort(快速排序),也可以传入mergesort(归并排序)或者是heapsort(堆排序) df.sort_values(by='col1')
df.sort_values(by=['col1', 'col2'])
DataFrame.astype(self, dtype, copy=True, errors='raise', **kwargs)
# dtype : data type, or dict of column name
# Use a numpy.dtype or Python type to cast entire pandas object to the same type. Alternatively, use {col: dtype, …}, where col is a column label and dtype is a numpy.dtype or Python type to cast one or more of the DataFrame’s columns to column-specific types. d = {'col1': [1, 2], 'col2': [3, 4]}
df = pd.DataFrame(data=d)
df.dtypes df.astype('int32').dtypes
df.astype({'col1': 'int32'}).dtypes
DataFrame.fillna(self, value=None, method=None, axis=None, inplace=False, limit=None, downcast=None, **kwargs)
# fillna()会填充nan数据,返回填充后的结果。如果希望在原DataFrame中修改,则把inplace设置为True
hdf5文件、tqdm模块、nunique、read_csv、sort_values、astype、fillna的更多相关文章
- (数据科学学习手札63)利用pandas读写HDF5文件
一.简介 HDF5(Hierarchical Data Formal)是用于存储大规模数值数据的较为理想的存储格式,文件后缀名为h5,存储读取速度非常快,且可在文件内部按照明确的层次存储数据,同一个H ...
- 使用h5py操作hdf5文件
HDF(Hierarchical Data Format)指一种为存储和处理大容量科学数据设计的文件格式及相应库文件.HDF 最早由美国国家超级计算应用中心 NCSA 开发,目前在非盈利组织 HDF ...
- 【Python 代码】生成hdf5文件
import random from PIL import Image import numpy as np import os import h5py from PIL import Image L ...
- 使用python操作HDF5文件
HDF Hierarchical Data Format,又称HDF5 在深度学习中,通常会使用巨量的数据或图片来训练网络.对于如此大的数据集,如果对于每张图片都单独从硬盘读取.预处理.之后再送入网络 ...
- nodejs零基础详细教程2:模块化、fs文件操作模块、http创建服务模块
第二章 建议学习时间4小时 课程共10章 学习方式:详细阅读,并手动实现相关代码 学习目标:此教程将教会大家 安装Node.搭建服务器.express.mysql.mongodb.编写后台业务逻辑 ...
- 【Python系列】HDF5文件介绍
一个HDF5文件是一种存放两类对象的容器:dataset和group. Dataset是类似于数组的数据集,而group是类似文件夹一样的容器,存放dataset和其他group.在使用h5py的时候 ...
- c++ 读取不了hdf5文件中的字符串
问题描述: 在拿到一个hdf5文件,想用c++去读取文件中的字符串,但是会报错:read failed ps: c++读取hdf5的字符串方法见:https://support.hdfgroup.or ...
- 关于php,python,javascript文件或者模块导入引入的区别和联系
前言: 我们经常看到编程语言之间,文件或者模块的引来引去的,但是他们在各个编程语言之间有什么区别和联系呢? 1.javascript (1).全局引入方式: <script src='xxxxx ...
- Tornado源码分析 --- 静态文件处理模块
每个web框架都会有对静态文件的处理支持,下面对于Tornado的静态文件的处理模块的源码进行分析,以加强自己对静态文件处理的理解. 先从Tornado的主要模块 web.py 入手,可以看到在App ...
随机推荐
- bzoj 4736: 温暖会指引我们前行 (LCT 维护最大生成树)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4736 题面: 寒冬又一次肆虐了北国大地 无情的北风穿透了人们御寒的衣物 可怜虫们在冬夜中发出 ...
- VMware HorizonView虚拟化桌面TLS问题处理
问题描述 公司虚拟化桌面环境内,进出口事业部同事在使用"中国贸易单一窗口"登录系统时,其系统本地控件无法启动WSS服务,端口显示使用61231,并反复提示安装控件. 排查过程 首先 ...
- [转帖]Java高级系列——注解(Annotations)
Java高级系列——注解(Annotations) 2018年01月13日 :: RonTech 阅读数 3405更多 所属专栏: Java高级系列文章 版权声明:转载请注明出处,谢谢配合. http ...
- Hadoop集群搭建-02安装配置Zookeeper
Hadoop集群搭建-05安装配置YARN Hadoop集群搭建-04安装配置HDFS Hadoop集群搭建-03编译安装hadoop Hadoop集群搭建-02安装配置Zookeeper Hado ...
- Spring的Bean的生命周期(大众版)
距离上一次写Spring源码解析,已经过去了快要好几个月了,主要原因还是Spring的源码解析类文章太难写了,不像我先前写的什么CAS源码,AQS源码,LinkedBlockingQueue等等, ...
- Spring4学习回顾之路05—自动装配,Bean的继承,依赖和作用域
自动装配 xml配置里的Bean的自动装配,Spring IOC容器可以自动装配Bean,仅仅需要做的是在<bean>标签里的autowire属性里指定自动装配的模式. ①byType(根 ...
- windows下将多个文件合并成一个文件,将ts文件变成MP3格式
①:先把全部的ts文件下载下来放到指定文件夹,这里我是放在桌面的ls里 ②:从cmd进去找到桌面的路径,也可以像我这样直接在桌面的路径上敲cmd进入: ③:直接合并使用命令“copy /b ls\*. ...
- socket传送文件格式的问题
在python3中socket传送文件只能传送‘bytes'类型,如下例子: import socket client = socket.socket()client.connect(("l ...
- Springboot导出Excel并下载
引入相关依赖 <!--数据导出excel--> <!-- https://mvnrepository.com/artifact/org.apache.poi/poi --> & ...
- Java EE javax.servlet中的ServletRequest接口
ServletRequest接口 public interface ServletRequest 子接口:HttpServletRequest 实现类:HttpServletRequestWrappe ...