![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
基础
文章平均质量分 78
格兰芬多的猫头鹰
努力up的小猫头鹰
展开
-
快速入门pandas扩展库(上)
快速入门pandas扩展库导入 Pandas 与 NumPy:In [1]: import numpy as npIn [2]: import pandas as pd2.生成对象用值列表生成 Series 时,Pandas 默认自动生成整数索引In [3]: s = pd.Series([1, 3, 5, np.nan, 6, 8])In [4]: sOut[4]:0 1.01 3.02 5.03 NaN4 6.05 8.0dtype: float64用含日期时间索原创 2020-11-19 18:28:18 · 286 阅读 · 2 评论 -
Python扩展库numpy示例快速理解(中)
1. 对数组进行函数运算>>> x=np.arange(0,100,10,dtype=np.floating)>>> xarray([ 0., 10., 20., 30., 40., 50., 60., 70., 80., 90.])>>> index=np.random.randint(0,len(x),5)>>> indexarray([9, 0, 3, 0, 2])>>> x[index]arra原创 2020-11-12 17:37:39 · 251 阅读 · 2 评论 -
Python扩展库numpy示例快速理解(上)
生成数组首先import numpy as np(我是在命令提示符里面调用的>>> np.array((1,2,3,4,5))array([1, 2, 3, 4, 5])>>> np.array(range(5))array([0, 1, 2, 3, 4])>>> np.array([[1,2,3],[4,5,6]])array([[1, 2, 3], [4, 5, 6]])>>> np.linspac.原创 2020-11-12 16:03:15 · 175 阅读 · 2 评论 -
将英文文本文件小写转大写
如何将英文文本文件小写转大写(以莎士比亚十四行诗为例)with open('Poem.txt','r') as f: all=f.readlines() new='' for i in all: for s in i: if s.islower(): new+=s.upper() elif s.isupper(): new+=s.lower()原创 2020-11-07 10:42:00 · 810 阅读 · 0 评论 -
用shelve模块读写二进制文件
特点:字典赋值,字典读取import shelvezhangsan={'age':38,'sex':'Male','address':'chengdu'}lisi={'age':23,'sex':'Female','tel':'110'}with shelve.open('shelve_test.dat') as fp: fp['zhangsan']=zhangsan fp['lisi']=lisiwith shelve.open('shelve_test.dat') as fp:原创 2020-11-07 10:11:29 · 181 阅读 · 0 评论 -
使用struct模块读取二进制文件
原创 2020-11-07 09:52:49 · 279 阅读 · 0 评论 -
pickle模块写二进制文件
pickle模块写二进制文件如图不过格式乱码求解答!!!原创 2020-11-07 00:09:59 · 191 阅读 · 0 评论 -
Python3 CSV写入文件
Python3 CSV写入文件1.写入结果如图原创 2020-11-06 23:29:10 · 140 阅读 · 0 评论 -
统计文本文件中最长行的内容和长度
1.txtwith open(‘1.txt’) as fp:result=[0,’’] #初始值for line in fp: #一个一个遍历t=len(line)if t>result[0]:result=[t,line] #t更大就重新赋值print(result)结果如图原创 2020-11-06 12:38:00 · 3751 阅读 · 0 评论 -
如何将数字升序排列后写入文件
如何将1.txt中的整数升序排序写入hi.txtwith open(‘1.txt’,‘r’) as f1:data=[line.strip() for line in f1.readlines()]data=’,’.join(data)data=data.split(’,’)data=[int(i) for i in data]data.sort()data=’,’.join(map(str,data))with open(‘hi.txt’,‘w’) as f2:f2.write(data原创 2020-11-06 12:14:33 · 626 阅读 · 0 评论