小编use*_*465的帖子

阻止Pandas将int转换为float

我有一个DataFrame.两个相关列如下:一列是列,int另一列是列str.

我明白,如果我插入NaNint列,熊猫将全部转化intfloat因为没有NaN一个值int.

然而,当我插入Nonestr列,熊猫都转换我intfloat为好.这对我来说没有意义 - 为什么第2列中的值会影响第1列?

这是一个简单的工作示例(Python 2):

import pandas as pd
df = pd.DataFrame()
df["int"] = pd.Series([], dtype=int)
df["str"] = pd.Series([], dtype=str)
df.loc[0] = [0, "zero"]
print df
print
df.loc[1] = [1, None]
print df
Run Code Online (Sandbox Code Playgroud)

输出是

   int   str
0    0  zero

   int   str
0  0.0  zero
1  1.0   NaN
Run Code Online (Sandbox Code Playgroud)

有没有办法使输出如下:

   int   str
0    0 …
Run Code Online (Sandbox Code Playgroud)

python pandas

19
推荐指数
2
解决办法
2万
查看次数

尝试使用MATLAB绘制z = x + y时图表不正确

我试图在MATLAB中绘制3D曲面,并且我使用了meshgrid,类似于MATLAB教程在这里所说的:http://www.mathworks.com/help/matlab/ref/meshgrid.html

我写了一个非常简单的三行脚本,我认为它会产生表面z = x + y,它如下:

[x , y] = meshgrid( linspace( 0 , 10 , 10 ) , linspace( 0 , 10 , 10 ) );
z = x + y;
surf( [ x , y , z] );
Run Code Online (Sandbox Code Playgroud)

根据我的理解,第1行产生(x,y)坐标的所有组合,从0到10均匀间隔.然后第2行将公式z = x + y应用于该详尽的组合列表.然后第3行只绘制所有(x, y, z)点.

但我得到以下"东西"作为输出:

z = x + y的错误图

我很确定上图中的图形不是z = x + y,我不知道为什么没有两个轴上升到最大值10.

尽管如此,我发现脚本太简单了,看不出有什么问题.任何人都可以指出我忽略了什么吗?谢谢.

matlab plot surface

4
推荐指数
1
解决办法
633
查看次数

HTML将文本与图像的按钮底部对齐

我有198px-198px的方形按钮.每个按钮下面都有一个图像和文字.由于并非所有图像都是正方形,因此我将所有图像的最大宽度和最大高度设置为128px,以便它们按比例缩放.不幸的是,我无法将文本与底部中心对齐.

我无法使用padding-top: 65px哪个解决了其他一些SO问题,因为图像的高度可变.

我尝试position: absolute; top: 180px了文本的范围,但我不能让它在那之后居中(不能只指定left: 10px因为文本有可变的长度)

谢谢你的帮助.

这是一个JSFiddle https://jsfiddle.net/vbgg3keu/3/ (注意:您可以扩展输出窗格的宽度,以便所有按钮在同一行上排成一行)

HTML:

<button class="square-button">
<img class="small-img" src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"/><br/>

<span class="button-text">This text is too high</span>
</button>

<button class="square-button">
<img class="small-img" src="http://etc.usf.edu/clipart/36400/36459/ruler1_36459_lg.gif"/><br/>

<span class="button-text">This text is too high</span>
</button>

<button class="square-button">
<img class="small-img" src="https://tall.life/wp-content/uploads/2013/04/Giraffe.jpg"/><br/>

<span class="button-text">This text is the correct height</span>
</button>

<button class="square-button">
<img class="small-img" src="https://lh3.googleusercontent.com/dB3Dvgf3VIglusoGJAfpNUAANhTXW8K9mvIsiIPkhJUAbAKGKJcEMPTf0mkSexzLM5o=w300"/><br/>

<span class="button-text">This text is the correct height</span>
</button>
Run Code Online (Sandbox Code Playgroud)

CSS:

.square-button {
  width: 198px;
  height: 198px;
  float: left;
}
.small-img …
Run Code Online (Sandbox Code Playgroud)

html css text-align text-alignment

3
推荐指数
1
解决办法
4947
查看次数

标签 统计

css ×1

html ×1

matlab ×1

pandas ×1

plot ×1

python ×1

surface ×1

text-align ×1

text-alignment ×1