有没有内置函数来丢弃整数并且只保留浮点数numpy.
import numpy as np
input = np.array([0.0, 0.01, 1.0, 2.0, 2.001, 2.002])
desired_ouput = some_function(input)
# Expected ouput
# desired_output = np.array([0.01, 2.001, 2.002])
Run Code Online (Sandbox Code Playgroud) 是否有任何内置方法numpy在应用str()方法后取回数组,例如,
import numpy as np
a = np.array([[1.1, 2.2, 3.3], [4.4, 5.5, 6.6]])
a_str = str(a)
#to get back a?
a = some_method(a_str).
Run Code Online (Sandbox Code Playgroud)
以下两种方法不起作用:
from ast import literal_eval
a = literal_eval(a_str) # Error
import numpy as np
a = np.fromstring(a_str) # Error
Run Code Online (Sandbox Code Playgroud)
更新 1:不幸的是,我已经用str()方法转换了非常大的数据,所以我不能用其他方法重新转换它。
考虑以下系列, ser
date id
2000 NaN
2001 NaN
2001 1
2002 1
2000 2
2001 2
2002 2
2001 NaN
2010 NaN
2000 1
2001 1
2002 1
2010 NaN
Run Code Online (Sandbox Code Playgroud)
如何计算值,以便计算并返回每个连续的数字?谢谢。
Count
NaN 2
1 2
2 3
NaN 2
1 3
NaN 1
Run Code Online (Sandbox Code Playgroud) 是否可以重置列,使它们成为第一行DataFrame.例如,
import pandas as pd
df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})
a b
0 1 4
1 2 5
2 3 6
Run Code Online (Sandbox Code Playgroud)
期望的输出,
df2 = df.reset_column() ???
0 1
0 a b
1 1 4
2 2 5
3 3 6
Run Code Online (Sandbox Code Playgroud)