![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python学习笔记
不吃虾米虾皮虾酱
GitHub&掘金:festinalente|CSDN主要记录零散内容
展开
-
sql常用汇总(python中)
未知长度参数params = df['name'].tolist()ph=','.join(['%s']*len(params))sql='select * from test.list1 where name in ({ph})'其实就是构建参数,加逗号和%s原创 2020-11-25 10:01:07 · 108 阅读 · 0 评论 -
pandas常用函数dataframe
pandas.Series.tolist----df['a'].tolist()原创 2020-11-25 09:52:02 · 953 阅读 · 2 评论 -
html实体转python unicode(终于解决了这个大难题,记录一下)
>>> import html>>> html.unescape('')'\ue650'因为在用dash写前端,大部分都是python。说实话这个除了上手简单一点都不好用,很多正常的写法都要转变一下才可以用。因为要使用iconfont,但是在阿里巴巴库中找到的只有html实体,要自己转换。作为一只菜鸡肯定是不会的,终于在https://blog.csdn.net/zhusongziye/article/details/78786519?u.原创 2020-09-08 10:25:39 · 270 阅读 · 0 评论 -
python返回标题化字符串(df)即所有单词首字母都大写
df['name'] = df['name'].str.title()原创 2020-08-28 13:43:47 · 402 阅读 · 0 评论 -
AttributeError: module ‘ntpath‘ has no attribute ‘splittext‘
AttributeError: module 'ntpath' has no attribute 'splittext'注意拼写!只有一个t正确答案:filename=os.path.splittext(file)[0]//取文件名suffix=os.path.splittext(file)[1]//取文件后缀原创 2020-08-28 09:25:56 · 8330 阅读 · 2 评论 -
python遍历文件夹输出所有文件的路径(需要文件名,文件后缀以及文件路径)用作下载链接
为了可以动态更新文件下载页面,现有需求:python遍历文件夹输出所有文件的路径(需要文件名,文件后缀以及文件路径)用作下载链接原创 2020-08-25 10:19:27 · 546 阅读 · 0 评论 -
python将NAT替换为空字符串(专业处理从数据库取出datetime数据的各种疑难杂症)
参考文章链接df['date_merge'] = pd.to_datetime(df['date_merge'], errors='coerce')df['date_merge'] = np.where(df.date_merge.notnull(),df.date_merge.dt.strftime('%Y-%m-%d %H:%M:%S'),'')从数据库取出的时间处理起来真的烦,终于在参考了很多文章之后找到了解决方案。。以上方案可以解决1.日期和时间中间的T;2.替换掉NAT...原创 2020-08-20 10:35:44 · 2768 阅读 · 5 评论 -
去掉datetime日期中间T(ISO格式时间),转为字符串
df['expiry_date'] = pd.to_datetime(df['expiry_date'], errors='coerce').dt.strftime('%Y-%m-%d')原创 2020-08-20 09:12:11 · 3867 阅读 · 0 评论 -
pandas dataframe整列变为小写
df['tolower'] = df['tolower'].str.lower()原创 2020-08-19 14:57:27 · 6496 阅读 · 0 评论 -
plotly|Dash学习笔记#4推荐一个dash组件dash-admin-components(图之后补)
Creating a fully resposive, beautiful dashboard withPlotly Dashhas never been easier!dash-admin-componentsrelies onshinydashboard implementationof AdminLTE3 template.It comes with preloaded Bootstrap 4 stylesheet that is fully compatibile withda...原创 2020-07-09 10:52:38 · 743 阅读 · 0 评论 -
plotly|Dash学习笔记#3如何利用dash组件下载文档
https://github.com/thedirtyfew/dash-extensions原创 2020-07-07 08:37:22 · 522 阅读 · 0 评论 -
plotly|Dash学习笔记#2 Clientside Callbacks报错:TypeError:cannot read property ‘color‘ of undefined
在使用Clientside Callbacks时,报错:TypeError:cannot read property 'color' of undefined,发现是js语法错误,直接用python写了。。。。改成js语法就没问题了。原创 2020-07-02 14:49:48 · 428 阅读 · 0 评论 -
plotly|Dash学习笔记#1 关于Basic Dash Callbacks中Input,Output和State的用法
主要是Input与State的选择,刚开始用的时候有点搞不清楚怎么选择,仔细看了文档其实理解起来很简单。下图例子是点击butto提交input中的value,因为Input中的内容,每次更改就会callback并Output,因此把value写在State中,value取最后一次更改的值,这样点击submit便可以提交。import dashimport dash_core_components as dccimport dash_html_components as htmlfrom da.原创 2020-06-29 14:30:01 · 1925 阅读 · 0 评论 -
ModuleNotFoundErrorNo module named pywin32_bootstrap
ModuleNotFoundError: No module named 'pywin32_bootstrap'用cmd安装pywin32之后出现如上错误,应该是权限不够。使用anaconda自带的powershell prompt再次安装,问题解决。原创 2020-06-17 09:05:25 · 1432 阅读 · 0 评论 -
uvicorn|更改fastapi服务器运行host和port
fastapi默认运行服务器的地址是:http://127.0.0.1:8000运行服务器指令为:uvicorn main:app --reload修改为:http://0.0.0.0:8080运行服务器指令为:uvicorn main:app --host '0.0.0.0'--port 8080 --reload...原创 2020-04-29 14:10:48 · 18522 阅读 · 12 评论 -
备忘|dataframe去掉含空值的行
df['a']=df['a'].fillna('null')df=df[~df['a'].isin(['null'])]取非空数据,dataframe去掉含空值的行原创 2020-04-28 14:46:12 · 2324 阅读 · 2 评论 -
ValueError: Out of range float values are not JSON compliant
是因为数据里面还有 nan不算完美的解决办法:df['a'] = df['a'].fillna(0)这样可以解决但空值都是0。原创 2020-04-26 14:03:01 · 6823 阅读 · 0 评论 -
既然python可以更高效处理数据,为何还要用sql取数?
这是知乎上的一个问题,也是我今天遇到的一个疑问,所以在此记录一下。取数的时候使用sql,可以降低空间成本,尤其是数据很多的时候,直接用dataframe不划算。计算的话用pandas。...原创 2020-04-20 10:21:27 · 266 阅读 · 1 评论 -
WARNING: pip is being invoked by an old script wrapper.
问题 WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip. Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue....原创 2020-04-19 09:52:13 · 4576 阅读 · 5 评论 -
MySQL创建唯一化索引并设置索引方式
使用sql语句创建唯一索引,格式如下:create unique index 索引名 on 表名(列名1,列名2……) using 方式名create unique index `unique_index_name` on `table_name`(`col_name`)USING BTREE#索引方式为:BTREEcreate unique index `unique_index_...原创 2020-03-24 10:29:50 · 1187 阅读 · 0 评论 -
fatal: unable to access 'https://github.com/xxx/xxx.git/': Failed to connect to 127.0.0.1 port
fatal: unable to access 'https://github.com/xxx/xxx.git/': Failed to connect to 127.0.0.1 port 1080: Connection refused在使用git pull的时候遇到了如上问题,因为之前因为vscode pull request 无法sign in,我设置了代理,所以出现这种问题把代理取消即...原创 2020-03-17 14:43:44 · 3541 阅读 · 3 评论 -
SQL|查重语句
SELECT name, COUNT(*) AS repeatFROM Table_1GROUP BY nameHAVING (COUNT(*) > 1)原创 2020-03-13 13:31:51 · 1034 阅读 · 0 评论 -
Python for Data Analysis|对列表或元组进行倒序排列若干方法
seq = [1,2,3,4,5,6,7]seq[::-1]output : [7, 6, 5, 4, 3, 2, 1]原创 2020-03-09 14:15:12 · 1518 阅读 · 0 评论 -
Python for Data Analysis|format格式化函数用法
最近在看《利用python进行数据分析》这本书,在元组这里有一个例子用到了format格式化函数,之前没遇到过,网上的示例代码似乎都一样,所以给大家提供一点不一样的参考。Jupyter:seq = [(1,2,3),(4,5,6),(7,8,9)]for a,b,c in seq: print('a={0},b={1},c={2}'.format(a,b,c))结果:...原创 2020-03-09 10:02:54 · 331 阅读 · 0 评论 -
fastapi教程翻译(搬运自用)
fastapi教程翻译(一):了解FastAPI结构fastapi教程翻译(二):Path参数fastapi教程翻译(三):Query参数fastapi教程翻译(四):Request Body(请求体)fastapi教程翻译(五):Query参数 & 字符串验证fastapi教程翻译(六):Path参数 & 数值验证fastapi教程翻译(七):Body -...转载 2020-02-27 11:16:14 · 2223 阅读 · 0 评论 -
Uvicorn 初体验-一个基于 asyncio 开发的一个轻量级高效的 Web 服务器框架
https://learnku.com/articles/25308/uvicorn-initial-experience-a-lightweight-efficient-web-server-framework-based-on-asyncio-development转载 2020-02-24 14:38:42 · 1707 阅读 · 0 评论 -
ASGI 异步服务网关接口规范中文译稿
https://blog.ernest.me/post/asgi-draft-spec-zh转载 2020-02-24 10:40:58 · 191 阅读 · 0 评论 -
if __name__ == '__main__' 如何正确理解
https://www.cnblogs.com/yaohong/p/8660209.html博主写的超级好,反正我是理解了。转载 2020-02-24 09:47:54 · 172 阅读 · 0 评论