python 之expenduser,dataframe.apply,np.fromstring

1)对于expenduser的说明:

参考链接:https://www.cnblogs.com/dkblog/archive/2011/03/25/1995537.html

os.path.abspath(path) #返回绝对路径
os.path.basename(path) #返回文件名
os.path.commonprefix(list) #返回list(多个路径)中,所有path共有的最长的路径。
os.path.dirname(path) #返回文件路径
os.path.exists(path)  #路径存在则返回True,路径损坏返回False
os.path.lexists  #路径存在则返回True,路径损坏也返回True
os.path.expanduser(path)  #把path中包含的"~"和"~user"转换成用户目录
os.path.expandvars(path)  #根据环境变量的值替换path中包含的”$name”和”${name}”
os.path.getatime(path)  #返回最后一次进入此path的时间。
os.path.getmtime(path)  #返回在此path下最后一次修改的时间。
os.path.getctime(path)  #返回path的大小
os.path.getsize(path)  #返回文件大小,如果文件不存在就返回错误
os.path.isabs(path)  #判断是否为绝对路径
os.path.isfile(path)  #判断路径是否为文件
os.path.isdir(path)  #判断路径是否为目录
os.path.islink(path)  #判断路径是否为链接
os.path.ismount(path)  #判断路径是否为挂载点()
os.path.join(path1[, path2[, ...]])  #把目录和文件名合成一个路径
os.path.normcase(path)  #转换path的大小写和斜杠
os.path.normpath(path)  #规范path字符串形式
os.path.realpath(path)  #返回path的真实路径
os.path.relpath(path[, start])  #从start开始计算相对路径
os.path.samefile(path1, path2)  #判断目录或文件是否相同
os.path.sameopenfile(fp1, fp2)  #判断fp1和fp2是否指向同一文件
os.path.samestat(stat1, stat2)  #判断stat tuple stat1和stat2是否指向同一个文件
os.path.split(path)  #把路径分割成dirname和basename,返回一个元组
os.path.splitdrive(path)   #一般用在windows下,返回驱动器名和路径组成的元组
os.path.splitext(path)  #分割路径,返回路径名和文件扩展名的元组
os.path.splitunc(path)  #把路径分割为加载点与文件
os.path.walk(path, visit, arg)  #遍历path,进入每个目录都调用visit函数,visit函数必须有
3个参数(arg, dirname, names),dirname表示当前目录的目录名,names代表当前目录下的所有
文件名,args则为walk的第三个参数
os.path.supports_unicode_filenames  #设置是否支持unicode路径名

2)dataframe.apply的说明:
参考链接:
http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.apply.html

 在这里,apply()当中的参数是lambda×(匿名函数)输入参数是:img,输出参数是:np.fromstring(img,sep=' ')



  
  
Parameters:

func : function

Function to apply to each column/row

axis : {0 or ‘index’, 1 or ‘columns’}, default 0

  • 0 or ‘index’: apply function to each column
  • 1 or ‘columns’: apply function to each row

broadcast : boolean, default False

For aggregation functions, return object of same size with valuespropagated

raw : boolean, default False

If False, convert each row or column into a Series. If raw=True thepassed function will receive ndarray objects instead. If you arejust applying a NumPy reduction function this will achieve muchbetter performance

reduce : boolean or None, default None

Try to apply reduction procedures. If the DataFrame is empty,apply will use reduce to determine whether the result should be aSeries or a DataFrame. If reduce is None (the default), apply’sreturn value will be guessed by calling func an empty Series (note:while guessing, exceptions raised by func will be ignored). Ifreduce is True a Series will always be returned, and if False aDataFrame will always be returned.

args : tuple

Positional arguments to pass to function in addition to thearray/series

Additional keyword arguments will be passed as keywords to the function

Returns:

applied : Series or DataFrame

 

Notes

In the current implementation apply calls func twice on thefirst column/row to decide whether it can take a fast or slowcode path.

This can lead to unexpected behavior if func hasside-effects, as they will take effect twice for the firstcolumn/row.

Examples

>>> df.apply(numpy.sqrt) # returns DataFrame
>>> df.apply(numpy.sum, axis=0) # equiv to df.sum(0)
>>> df.apply(numpy.sum, axis=1) # equiv to df.sum(1)


3)np.fromstring

参考链接:

https://docs.scipy.org/doc/numpy/reference/generated/numpy.fromstring.html


Parameters:

string : str

A string containing the data.

dtype : data-type, optional

The data type of the array; default: float. For binary input data,the data must be in exactly this format.

count : int, optional

Read this number of dtype elements from the data. If this isnegative (the default), the count will be determined from thelength of the data.

sep : str, optional

If not provided or, equivalently, the empty string, the data willbe interpreted as binary data; otherwise, as ASCII text withdecimal numbers. Also in this latter case, this argument isinterpreted as the string separating numbers in the data; extrawhitespace between elements is also ignored.

Returns:

arr : ndarray

The constructed array.

Raises:

ValueError

If the string is not the correct size to satisfy the requesteddtype and count.


Examples

>>> np.fromstring('\x01\x02', dtype=np.uint8)
array([1, 2], dtype=uint8)
>>> np.fromstring('1 2', dtype=int, sep=' ')
array([1, 2])
>>> np.fromstring('1, 2', dtype=int, sep=',')
array([1, 2])
>>> np.fromstring('\x01\x02\x03\x04\x05', dtype=np.uint8, count=3)
array([1, 2, 3], dtype=uint8)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值