我正在尝试将A
中dataframe
的列的dtype(float64
)从int
转换为df['A'].astype(numpy.int64)
,
A
但在此之后,float64
仍然以@Override
public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
// Calculate distances
float initialDistance = initialPointer1.dst(initialPointer2);
float distance = pointer1.dst(pointer2);
// Calculate pinch coordinates
float initialPinchX = (initialPointer1.x + initialPointer2.x) / 2;
float initialPinchY = (initialPointer1.y + initialPointer2.y) / 2;
float pinchX = (pointer1.x + pointer2.x) / 2;
float pinchY = (pointer1.y + pointer2.y) / 2;
// This to avoid first time zooming or panning horrible behavior
if (lastZoomDistance == 0) {
lastZoomDistance = initialDistance;
}
if (lastPinchX == lastPinchY && lastPinchX == 0) {
lastPinchX = initialPinchX;
lastPinchY = initialPinchY;
}
// Zoom
float distanceDifference = distance - lastZoomDistance;
camera.zoom -= distanceDifference / 300;
// Pan
float deltaX = (pinchX - lastPinchX) * camera.zoom;
float deltaY = (pinchY - lastPinchY) * camera.zoom;
camera.translate(-deltaX, deltaY);
// We need to update these for future calculations
lastZoomDistance = distance;
lastPinchX = (pointer1.x + pointer2.x) / 2;
lastPinchY = (pointer1.y + pointer2.y) / 2;
return false;
}
作为dtype。我想知道如何解决这个问题。
答案 0 :(得分:3)
您的输出似乎没有分配回来,所以需要:
df['A'] = df['A'].astype(numpy.int64)
如果NaNs
使用fillna
将其转换为int
:
df['A'] = df['A'].fillna(0).astype(numpy.int64)
或者NaN
列A
列中的df = df.dropna('A')
df['A'] = df['A'].astype(numpy.int64)
s删除所有行:
switch (this.state.selectedOption) {
case 'fifthOption':
return <FifthComponent />;
/*use span instead of div in every odd option,
so they mixed up "span - div - span - div" and so on*/
case 'firstOption': //
case 'thirdOption':
return (
<span className="wrapper">
<span className="title">{this.state.selectedOption}</span>
</span>);
default:
return (
<div className="wrapper">
<span className="title">{this.state.selectedOption}</span>
</div>);
}
答案 1 :(得分:1)
如果您有NaN值,那么Pandas无法将其转换为int
。
但很可能你只是没有将结果分配回A
专栏(正如@jezrael已经说过的那样)。
如果您尝试将NaN&#39转换为整数,则会出现以下异常:
In [4]: df = pd.DataFrame({'A':[1,2,np.nan,4]})
In [5]: df
Out[5]:
A
0 1.0
1 2.0
2 NaN
3 4.0
In [6]: df['A'] = df['A'].astype(np.int64)
...
skipped
...
ValueError: Cannot convert non-finite values (NA or inf) to integer