摘要: get 可以在没有key的情况下, 返回None. 防止程序跑飞. 阅读全文
posted @ 2023-05-07 14:53 清源居士 阅读(34) 评论(0) 推荐(0) 编辑
摘要: refer to: https://segmentfault.com/a/1190000014581721 阅读全文
posted @ 2023-04-13 16:33 清源居士 阅读(51) 评论(0) 推荐(0) 编辑
摘要: 将文本代码编译成Python可执行代码,这个代码对象可以通过eval()或exec()函数执行。 compile()函数的语法如下: compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1) 参数说明: sou 阅读全文
posted @ 2023-04-13 15:47 清源居士 阅读(446) 评论(0) 推荐(0) 编辑
摘要: 有些unicode编码无法转为gbk编码. 比如这个字, [䓬], 在转为gbk编码就会出现错误. 偷懒的办法是加上ignore选项. refer to: https://www.w3schools.com/python/ref_string_encode.asp https://blog.csdn 阅读全文
posted @ 2022-05-01 12:06 清源居士 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 两种方法: df = pd.DataFrame(df_raw, columns=['a', 'b']) df = df_raw[['a', 'b']] 阅读全文
posted @ 2021-11-10 18:29 清源居士 阅读(70) 评论(0) 推荐(0) 编辑
摘要: refer to: https://zhuanlan.zhihu.com/p/366856240 阅读全文
posted @ 2021-09-26 16:38 清源居士 阅读(13) 评论(0) 推荐(0) 编辑
摘要: from datetime import datetime today = datetime.now().weekday() print("0表示周一,2表示周二,...,6表示周日") print('查看今天周几:') print(today) week=datetime.strptime("20 阅读全文
posted @ 2021-02-25 15:47 清源居士 阅读(1772) 评论(0) 推荐(0) 编辑
摘要: urllib.request.urlopen getheader('Content-Disposition') 发现取出来的是乱码. 最后查到问题出在浏览器的编码上. 解决方法: s1.encode('ISO8859-1').decode('gbk') // 使用chrome 1, IE浏览器,采用 阅读全文
posted @ 2021-02-17 16:50 清源居士 阅读(675) 评论(0) 推荐(0) 编辑
摘要: from socket import timeout try: response = urllib.request.urlopen(url, timeout=10).read().decode('utf-8') except (HTTPError, URLError) as error: loggi 阅读全文
posted @ 2021-01-25 19:26 清源居士 阅读(461) 评论(0) 推荐(0) 编辑
摘要: pip install markdown -i https://pypi.tuna.tsinghua.edu.cn/simplerefer to:https://zhuanlan.zhihu.com/p/109939711 阅读全文
posted @ 2021-01-23 17:10 清源居士 阅读(86) 评论(0) 推荐(0) 编辑
摘要: 通过webrowser的open方法来打开: python的webbrowser模块支持对浏览器进行一些操作,主要有以下三个方法: 1.webbrowser.open(url, new=0, autoraise=True) 2.webbrowser.open_new(url) 3.webbrowse 阅读全文
posted @ 2020-12-17 15:15 清源居士 阅读(481) 评论(0) 推荐(0) 编辑
摘要: os.system 可以执行一个文件, 如果需要判断执行是否正常, 可以用它的返回值, rst = os.system('xxxxx.py') rst == 0, 正常. 否则, 出错. (似乎结果是1) 阅读全文
posted @ 2020-11-18 22:18 清源居士 阅读(5390) 评论(0) 推荐(0) 编辑
摘要: refer to: https://blog.csdn.net/CuGBabyBeaR/article/details/25037687 https://blog.csdn.net/Jarry_cm/article/details/99684387 四种方式, 1, 3最快 1) for i in 阅读全文
posted @ 2020-11-04 17:11 清源居士 阅读(1817) 评论(0) 推荐(0) 编辑
摘要: refer to : https://blog.csdn.net/u013700771/article/details/103321783 写的不错 阅读全文
posted @ 2020-08-08 21:21 清源居士 阅读(3758) 评论(0) 推荐(0) 编辑
摘要: https://www.pynote.net/archives/1248 阅读全文
posted @ 2020-08-08 19:36 清源居士 阅读(740) 评论(0) 推荐(0) 编辑
摘要: https://blog.csdn.net/qq_35528593/article/details/74453104 阅读全文
posted @ 2020-08-08 16:44 清源居士 阅读(291) 评论(0) 推荐(0) 编辑
摘要: https://blog.csdn.net/u011418971/article/details/88417620 https://blog.csdn.net/u011418971/article/details/88415253 阅读全文
posted @ 2020-07-20 22:29 清源居士 阅读(1856) 评论(0) 推荐(0) 编辑
摘要: https://blog.csdn.net/weixin_43213268/article/details/88932999 阅读全文
posted @ 2020-07-18 22:04 清源居士 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 查看指定值在列表中的位置,index方法:a_list.index('a') //返回a在列表中每一次出现的位置,默认搜索整个列表a_list.index('a',0,3) //返回a在指定切片内第一次出现的位置 阅读全文
posted @ 2020-07-14 19:48 清源居士 阅读(8081) 评论(0) 推荐(0) 编辑
摘要: In [24]: pandas.to_datetime('2012-05-01T01:00:00.000000+0100') Out[24]: datetime.datetime(2012, 5, 1, 1, 0, tzinfo=tzoffset(None, 3600)) 阅读全文
posted @ 2020-07-08 00:06 清源居士 阅读(1126) 评论(0) 推荐(0) 编辑
摘要: 为了保留原始的数字字符串的格式,可以指定dtype=str,来将原始数据按字符串格式导入: df2 = pd.read_excel('numeric.xlsx',dtype=str) 阅读全文
posted @ 2020-05-27 07:43 清源居士 阅读(2723) 评论(0) 推荐(0) 编辑
摘要: 字典合并: def merge(x,y): z = x.copy() z.update(y) return z 阅读全文
posted @ 2020-05-27 07:36 清源居士 阅读(301) 评论(0) 推荐(0) 编辑
摘要: 主要考虑如何控制台输出对齐的问题 refer tto: https://www.jianshu.com/p/5c9af81fd254 阅读全文
posted @ 2020-05-20 17:25 清源居士 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 三种函数的含义: 1.days:来获取时间差的天数 2.seconds:来获取时间差中的秒数。注意,seconds获得的秒只是时间差中的小时、分钟和秒部分的和,并没有包含时间差的天数 3.total_seconds:来获取准确的时间差,并将时间差转换为秒 阅读全文
posted @ 2020-05-20 08:29 清源居士 阅读(4784) 评论(0) 推荐(0) 编辑
摘要: 加上参数index_col=0 pd.read_csv(path, index_col=0)或pd.to_csv(path, index=False) 阅读全文
posted @ 2020-05-04 13:45 清源居士 阅读(3312) 评论(0) 推荐(0) 编辑
摘要: python中格式化字符 %% ,可以输出%,如下:>>> print '%.2f%%' % (1.234) 1.23% >>> print '%d%%' % 6868% %% 第一个%是转义的作用 阅读全文
posted @ 2020-03-08 01:15 清源居士 阅读(7236) 评论(1) 推荐(1) 编辑
摘要: refer to, https://saucer-man.com/operation_and_maintenance/298.html https://www.cnblogs.com/geaozhang/p/7111961.html https://www.jianshu.com/p/16701cd 阅读全文
posted @ 2020-02-09 14:50 清源居士 阅读(196) 评论(0) 推荐(0) 编辑
摘要: 老大难问题 http://blogs.360.cn/post/%E6%B5%85%E8%B0%88python%E4%B8%AD%E7%9A%84%E7%BC%96%E7%A0%81%E9%97%AE%E9%A2%98.html https://segmentfault.com/a/11900000 阅读全文
posted @ 2019-02-26 21:25 清源居士 阅读(205) 评论(0) 推荐(0) 编辑
摘要: import chardet f = open('/path/file.txt',r) data = f.read() print(chardet.detect(data) 阅读全文
posted @ 2019-02-25 19:12 清源居士 阅读(1658) 评论(0) 推荐(0) 编辑
摘要: b = [i[0] for i in a] # 从a中的每一行取第一个元素。 阅读全文
posted @ 2019-01-24 15:39 清源居士 阅读(6942) 评论(1) 推荐(0) 编辑