我有以下代码:
x = pd.DataFrame(np.zeros((4, 1)), columns=['A'])
y = np.random.randn(4, 2)
x['A'] = y
Run Code Online (Sandbox Code Playgroud)
我希望它因为形状不匹配而抛出异常.但是熊猫默默地接受了这个任务:y第一列被分配给了x.
这是故意设计吗?如果是的话,背后的理由是什么?
我尝试了pandas0.21和0.23.
感谢那些试图帮助的人.然而,尽管赏金即将到期,但没有人给出满意的答案.
让我强调一下预期的答案:
由于赏金即将到期,我接受了最多的投票答案.但它没有提供上述问题的答案.
我创建了以下脚本.你们中的任何人都可以向我解释为什么输出如下所示
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
print('debug', logger.isEnabledFor(logging.DEBUG))
print('info', logger.isEnabledFor(logging.INFO))
print('warning', logger.isEnabledFor(logging.WARNING))
print('error', logger.isEnabledFor(logging.ERROR))
logger.debug('debug')
logger.info('info')
logger.warning('warning')
logger.error('error')
logging.debug('debug')
logging.info('info')
logging.warning('warning')
logging.error('error')
Run Code Online (Sandbox Code Playgroud)
debug True
info True
warning True
error True
warning
error
DEBUG:root:debug
INFO:root:info
WARNING:root:warning
ERROR:root:error
Run Code Online (Sandbox Code Playgroud)
特别
logger.info和logging.info这里有什么区别
既然如此,那logger.isEnabledFor(logging.DEBUG)就是True虽然logger.debug('debug')没有显示任何东西
怎么logger.info没有输出logging.info却有
我很难理解cppreference引用的有关普通默认构造函数的以下段落。我已经搜索了stackoverflow,但仍然没有一个明确的答案。所以请帮忙。
普通的默认构造函数是不执行任何操作的构造函数。与C语言兼容的所有数据类型(POD类型)都是默认可构造的。但是,与C语言不同,不能通过简单地重新解释适当对齐的存储来创建具有琐碎默认构造函数的对象,例如,使用std :: malloc分配的内存:正式引入新对象并避免潜在的未定义行为时需要placement-new。
具体来说,如果琐碎的默认构造函数什么都不做,为什么我们不能重新解释存储并假装存在具有给定类型的对象?您能否提供一些可能导致未定义行为的示例?
在ipython笔记本项目重命名为jupyter之后,我总是认为它ipython notebook是相同的,jupyter notebook而ipythonshell只是别名jupyter console.今天我意识到ipython没有connect_info魔法定义,因此无法从不同的后端连接.
我的conda中安装了以下组件:
ipython 6.1.0 py36_0 defaults
jupyter 1.0.0 py36_4 defaults
jupyter_client 5.2.3 py36_0 defaults
jupyter_console 5.2.0 py36he59e554_1 defaults
jupyter_contrib_core 0.3.3 py36_1 conda-forge
jupyter_contrib_nbextensions 0.5.0 py36_0 conda-forge
jupyter_core 4.4.0 py36h7c827e3_0 defaults
Run Code Online (Sandbox Code Playgroud)
我有以下问题:
ipython这个版本和jupyter console这个版本之间有什么关系?ipython notebook(ipython 6.1.0另有弃用)是否与jupyter库共享一些组件; 或者ipython notebook仍然是独立的?ipython和jupyter有任何相关性?如果我使用git commit --amend,那么先前的提交(例如提交 A)将被覆盖,因为记住了它,所以它并不是完全无法访问的git reflog。
我的问题是:
git push,提交 A 是否会被推送到远程?git reflog expire --expire-unreachable=now使引用日志忘记提交 A 之后)我定义了以下小部件
function cdd()
{
cd /
}
zle -N cdd{,}
bindkey "^R" cdd
Run Code Online (Sandbox Code Playgroud)
按下组合键后,cwd 已更改,但终端提示未更新。例子,做完这个()
~/tmp/todelete$ | # press key ^R here; "~$" is the prompt; "|" denotes cursor
Run Code Online (Sandbox Code Playgroud)
终端保持完全不变。如果我然后输入ls -ld .,它会显示
~/tmp/todelete$ ls -ld .
dr-xr-xr-x 23 root root 4096 Sep 14 07:52 ./
/$ |
Run Code Online (Sandbox Code Playgroud)
这意味着cwd当时ll正在运行的已经是/.
这是非常混乱的,可能会导致严重的错误。(例如,如果按下后^R我被打扰离开我的办公桌然后回来,我可能会忘记我做了什么)
如何让终端在按键后重新绘制提示?有没有一个zle功能可以做到这一点?
我觉得zsh即使在函数内调用它也会扩展别名,例如
alias abc='echo abc'
function fabc(){abc}
Run Code Online (Sandbox Code Playgroud)
是否可以在此函数中禁用别名扩展?
还有一个相关问题:是否可以在整个交互式 shell 中禁用别名扩展?
是否可以使用Cell Magic将类添加到输出单元?例如:
In [1]: %%css-class highlight
display(pd.DataFrame(np.random.rand(3,4)))
Run Code Online (Sandbox Code Playgroud)
然后该单元格Out [1]将具有“突出显示”类,以便我可以使用CSS更改格式。
我读了文档history,上面写着:
history [n]
history -c
history -d offset
history -anrw [filename]
history -p arg [arg ...]
history -s arg [arg ...]
With no options, display the command history list with line
numbers. Lines listed with a * have been modified. An
argument of n lists only the last n lines.
Run Code Online (Sandbox Code Playgroud)
但是在我的zsh中,它始终显示前n行。我需要使用history | tail -n来显示最后几行。
这里我特别只关心GCC编译器和运行时代码的效率。
考虑下面的代码试试我
#include <iostream>
#include <map>
char Find(const std::map<int, char>& map, int key) {
auto iter = map.find(key);
if (iter == map.end())
return 'X';
return iter->second;
}
char Find2(const std::map<int, char>& map, int key) {
return map.find(key)->second;
}
int main()
{
// part 1
std::map<int, char> x{{0,'0'}, {4,'4'}};
std::cout << Find(x, 3) << std::endl;
std::cout << Find(x, 4) << std::endl;
std::cout << (int)Find2(x, 3) << std::endl; // returns 0
std::cout << Find2(x, 4) << std::endl;
// part 2: Find2 …Run Code Online (Sandbox Code Playgroud)