有没有办法使用isoformats提取月和日?让我们假设今天的日期是2013年3月8日.
>>> d = datetime.date.today()
>>> d.month
3
>>> d.day
8
Run Code Online (Sandbox Code Playgroud)
我想要:
>>> d = datetime.date.today()
>>> d.month
03
>>> d.day
08
Run Code Online (Sandbox Code Playgroud)
我可以通过编写if语句和连接前导0来实现这一点,以防日期或月份是单个数字但是想知道是否有自动生成我想要的方法.
如何在MySQL中的日期范围之间选择数据.我的datetime专栏采用24小时zulu时间格式.
select * from hockey_stats
where game_date between '11/3/2012 00:00:00' and '11/5/2012 23:59:00'
order by game_date desc;
Run Code Online (Sandbox Code Playgroud)
尽管在这些时间段之间有数据,但不返回任 我是否必须强制"从"和"到"字段中的值才能datetime在查询中键入?
我有一个定义表,我知道它没有得到很好的维护,让我们称之为table A.我有另一个表(称之为table B),它更小,理想情况下应该是一个,subset of table A但我知道这table A有点陈旧,并且不包含新的条目Table B.
注意,表A和表B具有不同的列.
Table A:
ID, Name, blah, blah, blah, blah
Table B:
ID, Name
Run Code Online (Sandbox Code Playgroud)
我想要表B中的所有行,表B中的ID不存在于表A中.这不仅仅匹配表A中的行; 我只想要表B中的行,其中表A中根本不存在ID.
我有一个脚本需要在脚本中的不同行执行以下操作:
today_date = datetime.date.today()
date_time = datetime.strp(date_time_string, '%Y-%m-%d %H:%M')
Run Code Online (Sandbox Code Playgroud)
在我的import语句中,我有以下内容:
from datetime import datetime
import datetime
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
AttributeError: 'module' object has no attribute 'strp'
Run Code Online (Sandbox Code Playgroud)
如果我将import语句的顺序更改为:
import datetime
from datetime import datetime
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
AttributeError: 'method_descriptor' object has no attribute 'today'
Run Code Online (Sandbox Code Playgroud)
如果我再次将import语句更改为:
import datetime
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
AttributeError: 'module' object has no attribute 'strp'
Run Code Online (Sandbox Code Playgroud)
这里发生了什么,如何让两者兼顾?欣赏它.谢谢.
我jupyter notebook的版本4.2我MacOS(10.9.5)
我jupyter lab在MacOS终端启动,它会在以下链接自动打开浏览器:http://localhost:8888/lab
此时我看到了Welcome to the JupyterLab Alpha preview屏幕,但仅此而已.没有标签等.请参阅我已包含的图像.
我正在使用Chromium(Version 43.0.2357.130 (64-bit)
).当我尝试在Safari浏览器中打开时绝对没有任何负载.它是空白的浏览器会话.
我在浏览器中看到的内容与我JupyterLab在youtube上的所有视频中看到的任何内容都不相同(PyData 2016 DC例如).
很明显,渲染有问题.
更新:
控制台中的输出:
WebSocket connection to 'ws://localhost:8888/terminals/websocket/1' failed: WebSocket is closed before the connection is established.
http://localhost:8888/api/contents/untitled.txt?1485120059877 Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8888/api/contents/DeleteMe.ipynb?1485120060078 Failed to load resource: the server responded with a status …Run Code Online (Sandbox Code Playgroud) 我有一个约会:
from datetime import datetime
from datetime import tzinfo
test = '2013-03-27 23:05'
test2 = datetime.strptime(test,'%Y-%m-%d %H:%M')
>>> test2
datetime.datetime(2013, 3, 27, 23, 5)
>>> test2.replace(tzinfo=EST)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'EST' is not defined
>> test2.replace(tzinfo=UTC)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'UTC' is not defined
Run Code Online (Sandbox Code Playgroud)
我找不到names可以在replace.tzinfo=调用中分配给tzinfo 的时区列表中的文档.
我已阅读以下内容,但没有任何内容:
http://docs.python.org/2/library/datetime.html#tzinfo-objects
我也在谷歌搜索过.
编辑:我按照unutbu提供的解决方案,但我得到以下内容:
>>> test = '2013-03-27 00:05'
>>> test …Run Code Online (Sandbox Code Playgroud) 我遵循以下说明:
https://bioconda.github.io/recipes/awscli/README.html#installation
Run Code Online (Sandbox Code Playgroud)
执行: conda install awscli
结果:
Fetching package metadata: ....
Solving package specifications: .
Error: Package missing in current osx-64 channels:
- awscli
You can search for this package on anaconda.org with
anaconda search -t conda awscli
You may need to install the anaconda-client command line client with
conda install anaconda-client
Run Code Online (Sandbox Code Playgroud) 我正在使用SQL Server(我相信它是2005年).
我有TableA2列和439行(每行是唯一的).
+----------+
|ID | Name |
+----------+
Run Code Online (Sandbox Code Playgroud)
我有TableB35列和数十万行(每行也是唯一的).
+------------------------------------------------------------------------------+
|Date | ID | Name | Blah1 | Blah2 | ... | Hour1 | Hour2 | Hour3 | ... | Hour24 |
+------------------------------------------------------------------------------+
Run Code Online (Sandbox Code Playgroud)
每行TableB都有每小时观察和其他一些管家信息.现在出于测试目的,我只对今天的日期即2013年4月19日感兴趣.
如果我做:
Select count(*)
from TableB
where Date = '4/19/2013 12:00:00 AM'
Run Code Online (Sandbox Code Playgroud)
我得到10526,这是正确的,因为有10526个不同的位置,每天有每小时观察数据.
我想LEFT JOIN TableA和TableB on a.id = b.id,它应该产生一个有439行的结果.
不幸的是,结果有246行.怎么会这样?不管是否匹配,都不是LEFT JOIN要返回所有行?TableATableB
*编辑*
我使用的完整查询是:
select *
from TableA as a
left join TableB …Run Code Online (Sandbox Code Playgroud) 我有一个看起来像的df:
df.head()
Out[1]:
A B C
city0 40 12 73
city1 65 56 10
city2 77 58 71
city3 89 53 49
city4 33 98 90
Run Code Online (Sandbox Code Playgroud)
可以通过以下代码创建示例df:
df = pd.DataFrame(np.random.randint(100,size=(1000000,3)), columns=list('ABC'))
indx = ['city'+str(x) for x in range(0,1000000)]
df.index = indx
Run Code Online (Sandbox Code Playgroud)
我想做的是:
a)确定A列的适当直方图桶长度,并将每个城市分配给A列的桶
b)确定B列的适当直方图桶长度,并将每个城市分配给B列的桶
也许结果df看起来像(或者是否有更好的内置方式在熊猫?)
df.head()
Out[1]:
A B C Abkt Bbkt
city0 40 12 73 2 1
city1 65 56 10 4 3
city2 77 58 71 4 3
city3 89 53 49 5 3
city4 33 98 90 …Run Code Online (Sandbox Code Playgroud) 根据 seaborn 文档,这里 seaborn.distplot()已被弃用,支持的图为:seaborn.displot()和seaborn.histplot()。
但是,当我尝试使用displot()或 时histplot()出现以下属性错误:
AttributeError: module 'seaborn' has no attribute 'displot'
注意我可以成功运行seaborn.jointplot()和其他各种。
我发现这个 SO post Module Seaborn 没有属性 ''但这似乎不是我问题的解决方案。
我已经seaborn版本0.10.1我安装的MacOS版本10.15.5(19F101)
我今天早些时候有seaborn 0.9.0并且遇到了同样的问题,所以我使用App Cleaner & Uninstaller应用程序删除了我的Anaconda发行版并重新安装。现在我有seaborn 版本 0.10.1。
Anaconda的全新安装不应该处理所有依赖项和要求吗?
请参见下面的属性错误屏幕截图。任何想法发生了什么?
更新:
上面的图似乎最近才从seaborn 0.11.0开始可用。所以我正在尝试通过以下方式安装新的 seaborn:conda install seaborn==0.11.0但是conda和/或频道似乎有问题。它试图解决环境问题,但它处于永无止境的循环中。我终止了这个过程,然后再试一次,同样的事情。
(base)MacBook-Air:$ conda install seaborn==0.11.0
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial …Run Code Online (Sandbox Code Playgroud)