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.

  1. df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}, index=['a', 'b', 'c'])
  2. 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
  3. s = pd.Series([1, 2, 3, 4])
  4. s.to_hdf('data.h5', key='s')
  5.  
  6. pd.read_hdf('data.h5', 'df')
  7. pd.read_hdf('data.h5', 's')

tqdm模块显示进度条:

  1. 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.

  1. for x in tqdm(train_df['request_timestamp'].values,total=len(train_df)):
  2. localtime=time.localtime(x)
  3. wday.append(localtime[6])
  4. hour.append(localtime[3])

https://lorexxar.cn/2016/07/21/python-tqdm/

https://tqdm.github.io/docs/tqdm/

pandas.DataFrame.nuniquehttps://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.nunique.html

DataFrame.nunique(selfaxis=0dropna=True)

Count distinct observations over requested axis. Return Series with number of distinct observations. Can ignore NaN values.

  1. >>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [1, 1, 1]})
  2. >>> df
  3. A B
  4. 0 1 1
  5. 1 2 1
  6. 2 3 1
  7. >>> df.nunique()
  8. A 3
  9. B 1
  10. dtype: int64
  11. >>> df.nunique(axis=1)
  12. 0 1
  13. 1 2
  14. 2 2
  15. dtype: int64

pandas.read_csv:

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.

  1. 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'])

pandas.DataFrame.sort_values:

  1. DataFrame.sort_values(self, by, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last')
  2. # axis这个参数的默认值为0,匹配的是index,跨行进行排序,当axis=1时,匹配的是columns,跨列进行排序
  3. # by这个参数要求传入一个字符或者是一个字符列表,用来指定按照axis的中的哪个元素来进行排序
  4. # ascending这个参数的默认值是True,按照升序排序,当传入False时,按照降序进行排列
  5. # kind这个参数表示按照什么样算法来进行排序,默认值是quicksort(快速排序),也可以传入mergesort(归并排序)或者是heapsort(堆排序)
  6.  
  7. df.sort_values(by='col1')
  8. df.sort_values(by=['col1', 'col2'])

pandas.DataFrame.astype:

  1. DataFrame.astype(self, dtype, copy=True, errors='raise', **kwargs)
  2. # dtype : data type, or dict of column name
  3. # 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.
  4.  
  5. d = {'col1': [1, 2], 'col2': [3, 4]}
  6. df = pd.DataFrame(data=d)
  7. df.dtypes
  8.  
  9. df.astype('int32').dtypes
  10. df.astype({'col1': 'int32'}).dtypes

pandas.DataFrame.fillna

  1. DataFrame.fillna(self, value=None, method=None, axis=None, inplace=False, limit=None, downcast=None, **kwargs)
  2. # fillna()会填充nan数据,返回填充后的结果。如果希望在原DataFrame中修改,则把inplace设置为True

hdf5文件、tqdm模块、nunique、read_csv、sort_values、astype、fillna的更多相关文章

  1. (数据科学学习手札63)利用pandas读写HDF5文件

    一.简介 HDF5(Hierarchical Data Formal)是用于存储大规模数值数据的较为理想的存储格式,文件后缀名为h5,存储读取速度非常快,且可在文件内部按照明确的层次存储数据,同一个H ...

  2. 使用h5py操作hdf5文件

    HDF(Hierarchical Data Format)指一种为存储和处理大容量科学数据设计的文件格式及相应库文件.HDF 最早由美国国家超级计算应用中心 NCSA 开发,目前在非盈利组织 HDF ...

  3. 【Python 代码】生成hdf5文件

    import random from PIL import Image import numpy as np import os import h5py from PIL import Image L ...

  4. 使用python操作HDF5文件

    HDF Hierarchical Data Format,又称HDF5 在深度学习中,通常会使用巨量的数据或图片来训练网络.对于如此大的数据集,如果对于每张图片都单独从硬盘读取.预处理.之后再送入网络 ...

  5. nodejs零基础详细教程2:模块化、fs文件操作模块、http创建服务模块

    第二章  建议学习时间4小时  课程共10章 学习方式:详细阅读,并手动实现相关代码 学习目标:此教程将教会大家 安装Node.搭建服务器.express.mysql.mongodb.编写后台业务逻辑 ...

  6. 【Python系列】HDF5文件介绍

    一个HDF5文件是一种存放两类对象的容器:dataset和group. Dataset是类似于数组的数据集,而group是类似文件夹一样的容器,存放dataset和其他group.在使用h5py的时候 ...

  7. c++ 读取不了hdf5文件中的字符串

    问题描述: 在拿到一个hdf5文件,想用c++去读取文件中的字符串,但是会报错:read failed ps: c++读取hdf5的字符串方法见:https://support.hdfgroup.or ...

  8. 关于php,python,javascript文件或者模块导入引入的区别和联系

    前言: 我们经常看到编程语言之间,文件或者模块的引来引去的,但是他们在各个编程语言之间有什么区别和联系呢? 1.javascript (1).全局引入方式: <script src='xxxxx ...

  9. Tornado源码分析 --- 静态文件处理模块

    每个web框架都会有对静态文件的处理支持,下面对于Tornado的静态文件的处理模块的源码进行分析,以加强自己对静态文件处理的理解. 先从Tornado的主要模块 web.py 入手,可以看到在App ...

随机推荐

  1. Python 清华镜像设置

    大家在通过pip 或conda 下载一些很大的第三方库时是不是有一种等到坟头的草都三尺高了,还没下载完的感觉,而且大的第三方库长时间下载,可能会导致超时自动中断下载,感谢清华的大佬们 临时使用: pi ...

  2. City Road

    题目描述 从前有一个叫做”H湖”的地方,”H湖”的居民生活在不同的小岛上,当他们想去其他的小岛时都要通过划小船或者小岛之间的桥来实现.现在政府想实现”H湖”的全畅通!(不一定有直接的桥相连,只要互相间 ...

  3. 多线程基础知识---join方法

    join方法的作用 thread.join()方法用于把指定的线程加入到当前线程中,把当前线程的CPU执行时间让给另一个线程.比如在线程B中调用了线程A的Join()方法,直到线程A执行完毕后,才会继 ...

  4. CWMP开源代码研究——git代码工程

    原创作品,转载请注明出处,严禁非法转载.如有错误,请留言! email:40879506@qq.com 声明:本系列涉及的开源程序代码学习和研究,严禁用于商业目的. 如有任何问题,欢迎和我交流.(企鹅 ...

  5. php 连接sqlserver

    本地环境windows 10+phpstudy2016+ SQL Server 2008 R2 x86+php7.0查看自己sql server 多少位可以在新建查询里输入 select @@VERS ...

  6. jwt认证规则

    目录 认证规则图 django不分离 drf分类 认证规则演变图 数据库session认证:低效 缓存认证:高效 jwt认证:高效 缓存认证:不易并发 jwt认证:易并发 JWT认证规则 优点 格式 ...

  7. T100——报表的小计数量、小计金额,总计金额

    范例:cxmr540_g01 范例代码: ON EVERY ROW #add-point:rep.everyrow.before name="rep.everyrow.before" ...

  8. PMP - 风险识别之风险登记册

    目录 PMP - 风险识别之风险登记册 1. 风险登记册 1.1 已识别风险的清单 1.2 潜在风险责任人 1.3 潜在风险应对措施清单 2. 相关习题 2.1 风险发生的时候,要实施 风险登记册 上 ...

  9. swagger2 Could not resolve pointer: /definitions

    错误信息: Errors Resolver error at paths././query.post.parameters.20.schema.$ref Could not resolve refer ...

  10. [Android] Installation failed due to: ''pm install-create -r -t -S 4590498' returns error 'UNSUPPORTED''

    小米特有问题 关闭开发者选项的启用MIUI优化 不得不说, 这是真的坑...