随笔分类 - python
摘要:将一个cookies字符串,转换为字典的方法
阅读全文
摘要:标准获取API接口的json文件 import requests import json url = 'https://api.github.com/search/repositories?q=language:python&sort=stars' try: r = requests.get(url
阅读全文
摘要:plotly.express 绘制 地震点 import plotly.express as px import pandas as pd import json filename = 'data/eq_data_1_day_m1.json' with open(filename) as f: #
阅读全文
摘要:增加一个容错判断,如果找不到数据,则抛出异常,,也可以用remove()或del将已提取的数据删除 import csv import matplotlib.pyplot as plt from datetime import datetime # 设置字体 # plt.rcParams['font
阅读全文
摘要:matplotlib构图 案例1 气温 import csv import matplotlib.pyplot as plt from datetime import datetime # 设置字体 # plt.rcParams['font.sans-serif'] = ['SimHei'] # 汉
阅读全文
摘要:在用 matplotlib.pyplot 进行绘图时加入中文字体,提示字体找不到,解决方法如下 1、百度下载 SimHei.ttf (黑体) 字体文件; 2、复制到 D:\Python38\Lib\site-packages\matplotlib\mpl-data\fonts\ttf 目录下(我的目
阅读全文
摘要:random_walk.py from random import choice class RandomWalk: """一个生成随机漫步数据的类。""" def __init__(self, num_points=5000): """初始化随机漫步的属性。""" self.num_points
阅读全文
摘要:1、win进入cmd后直接安装 python -m pip install --user plotly 2、cmd 进入后找到python的安装目录,找到pip.exe文件的同级目录,执行 pip3 install requests 3、安装matplotlib模块 python -m pip in
阅读全文
摘要:a = datetime.now().strftime('%Y-%m-%d') print(a)
阅读全文
摘要:为了给孩子出随机口算题,几行代码搞定! import random def cale(minnum, maxnum, operator, maxsum=None, minsum=None): """随机出数学计算题""" while True: a = random.randint(minnum,
阅读全文
摘要:平时在用Pycharm的时候注意到在补全函数提示词前面有c,m,p等小分类,这些到底是什么意思呢,一起看一下吧! c 代表Class:类m 代表Method:类实例方法F 代表Function:函数f 代表Field:类属性,域v代表Variable:变量p 代表Property:python内置函
阅读全文
摘要:Rect对象的属性:1.返回一个坐标数字x,ytop, left, bottom, rightcenterx, centerysizewidth, heightw,h;2.返回一个(X,Y)坐标数组topleft (左上)bottomleft (左下)bottomright (右下)midtop(中
阅读全文
运行python文件报SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: tr
摘要:刚刚在运行python文件的时候竟然报SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: tr这个错误,其实引起这个错误的原因就是转义的问题。 sys.path.append('
阅读全文
摘要:Python 批量查找文件中含有关键字的文件,并存储到新文件中 import os from re import T path = r'F:\pass\pass' # 绝对路径目录 files = os.listdir(path) # 得到文件夹下的所有文件名称 for file in files:
阅读全文
摘要:实则就是重新写一遍文件内容,将匹配的行记录 跳过(continue),,但是如果目标文件是好几个G的文件,那这样会十分耗时甚至内存溢出吧~! with open("pi.txt", "r") as f: lines = f.readlines() print(lines) with open("pi
阅读全文
摘要:Python文本读取 按关键字查找文件内容,并保存为文件 from os import replace import re file = "d:/gdshnd_scm_0.txt" with open(file) as f: content = f.readlines() if content: f
阅读全文
摘要:函数isinstance()可以判断一个变量的类型,既可以用在Python内置的数据类型如str、list、dict,也可以用在我们自定义的类,它们本质上都是数据类型。 假设有如下的 Person、Student 和 Teacher 的定义及继承关系如下: class Person(object):
阅读全文