我有一个c ++函数read_inputdata来读取一些inputfile并将值写入一个数组.我首先声明一个适当长度的数组,并使用函数我用输入文件中的值填充它.
但是我遇到了分段错误.有谁知道我做错了什么?
#define MAX 140160
void read_inputdata(double input[MAX], char files[40]);
char inputfiles1[40] = "input/Hesse04/FR_Hes_rad.txt";
std::cout << "Declaring the arrays" << std::endl;
double input1[MAX];
std::cout << "Calling function read_inputdata" << std::endl;
read_inputdata(input1, inputfiles1);
Run Code Online (Sandbox Code Playgroud)
当我编译并运行它时,我得到:
Declaring the arrays
Calling function read_inputdata
Segmentation fault
Run Code Online (Sandbox Code Playgroud)
所以目前他称这个功能read_inputdata出了问题,因为他没有达到std::cout << "In function read_inputdata" << std::endl;.
功能:
void read_inputdata(double input[MAX], char files[40])
{
std::cout << "In function read_inputdata" << std::endl;
std::ifstream inputfile;
inputfile.open(files);
if (inputfile.is_open())
{
char temp[100];
double getal[2][MAX];
int …Run Code Online (Sandbox Code Playgroud) 我正在尝试读取一个csv文件,其中一个示例:
datetime,check,lat,lon,co_alpha,atn,status,bc
2012-10-27 15:00:59,2,0,0,2.427,,,
2012-10-27 15:01:00,2,0,0,2.407,,,
2012-10-27 15:02:49,2,0,0,2.207,-17.358,0,-16162
2012-10-27 15:02:50,2,0,0,2.207,-17.354,0,8192
2012-10-27 15:02:51,1,0,0,2.207,-17.358,0,-8152
2012-10-27 15:02:52,1,0,0,2.207,-17.358,0,648
2012-10-27 15:06:03,0,51.195076,4.444407,2.349,-17.289,0,4909
2012-10-27 15:06:04,0,51.195182,4.44427,2.344,-17.289,0,587
2012-12-05 09:21:34,,,,,42.960,1,16430
2012-12-05 09:21:35,,,,,42.962,1,3597
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是在只有整数的列中,0被转换为NaN(例如列'check'和'status',这些是只有整数的列,但是这些列被读作浮点因为有真正的缺失值) .但我只想将空值转换为NaN,而不是零.
这就是我得到的:
>>> pd.read_clipboard(sep=',', parse_dates=True, index_col=0)
check lat lon co_alpha atn status bc
datetime
2012-10-27 15:00:59 2 0.000000 0.000000 2.427 NaN NaN NaN
2012-10-27 15:01:00 2 0.000000 0.000000 2.407 NaN NaN NaN
2012-10-27 15:02:49 2 0.000000 0.000000 2.207 -17.358 NaN -16162
2012-10-27 15:02:50 2 0.000000 0.000000 2.207 -17.354 NaN 8192
2012-10-27 15:02:51 1 0.000000 0.000000 2.207 -17.358 …Run Code Online (Sandbox Code Playgroud) 知道为什么会有这样的行为吗?
基础数据:
In [1]: tmc_sum.head(6)
Out [1]: 1 2 3 8 9 10
tmc
110+05759 7469 7243 7307 7347 7271 7132
110P05759 7730 7432 7482 7559 7464 7305
110+05095 7256 6784 6697 6646 6786 6530
110P05095 0 0 0 0 0 0
110+05096 6810 5226 5625 5035 5064 4734
110P05096 6854 5041 5600 5308 5261 4747
Run Code Online (Sandbox Code Playgroud)
序幕:
根据quantile 的文档,这可以正常工作:
In [2]: tmc_sum.quantile(0.05, axis=1)
Out [2]: 1 3347.50
2 1882.40
3 1933.10
8 1755.00
9 1554.15
10 1747.85
dtype: …Run Code Online (Sandbox Code Playgroud) 我正在使用Python 2.7并继续得到以下错误.如果您需要完整的代码,请告诉我,但它有点长.谢谢您的帮助.
Warning (from warnings module):
File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 3619
FutureWarning)
FutureWarning: TimeSeries broadcasting along DataFrame index by default is deprecated.
Please use DataFrame.<op> to explicitly broadcast arithmetic operations along the index
Run Code Online (Sandbox Code Playgroud)
这是班级投资组合
class Portfolio(object):
"""An abstract base class representing a portfolio of
positions (including both instruments and cash), determined
on the basis of a set of signals provided by a Strategy."""
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def generate_positions(self):
raise NotImplementedError("Should implement generate_positions()!")
@abc.abstractmethod
def backtest_portfolio(self):
raise NotImplementedError("Should implement backtest_portfolio()!")
Run Code Online (Sandbox Code Playgroud)
这是在<<<< …