I have a list of lists called final_result, with the following structure:
[[Pandas Dataframe, int], [Pandas Dataframe, int], [Pandas Dataframe, int], ...]
When I run:
for i in final_result:
print(final_result.index(i))
if int(final_result.index(i)) != 0:
print("got here")
else: print("got here2")
I get the following traceback:
Traceback (most recent call last):
File "backtest.py", line 471, in backtest_mt
print(final_result.index(i))
File "C:\Users\eyese\.julia\conda\3\lib\site-packages\pandas\core\ops\__init__.py", line 839, in f
"Can only compare identically-labeled DataFrame objects"
ValueError: Can only compare identically-labeled DataFrame objects
Yet, the correct index, 0, and "got here2" actually gets printed to the console prior to the function breaking. I tried removing the print command, and it then breaks on the if statement (and consequently 0 does not get printed to the console, but "got here2" still does). This is surpising, as it seems to run through the function once until breaking at the print statement. What would be the correct way to retrieve the index of a first-layer list within this kind of list of lists?
Sample data:
[[ timestamp capital
0 2020-05-25 17:14:00+00:00 1000
1 2020-05-25 17:15:00+00:00 1000
2 2020-05-25 17:16:00+00:00 1000
3 2020-05-25 17:17:00+00:00 1000
4 2020-05-25 17:18:00+00:00 1000
.. ... ...
957 2020-05-26 09:12:00+00:00 999.925
958 2020-05-26 09:13:00+00:00 999.925
959 2020-05-26 09:14:00+00:00 999.925
960 2020-05-26 09:15:00+00:00 1000.2
961 2020-05-26 09:16:00+00:00 1000.2
[962 rows x 2 columns], 1000.1964074198233], [ timestamp capital
0 2020-05-26 09:16:00+00:00 1000
1 2020-05-26 09:17:00+00:00 1000
2 2020-05-26 09:18:00+00:00 1000
3 2020-05-26 09:19:00+00:00 1000
4 2020-05-26 09:20:00+00:00 1000
... ... ...
1887 2020-05-27 16:45:00+00:00 1001.03
1888 2020-05-27 16:46:00+00:00 1001.03
1889 2020-05-27 16:47:00+00:00 1001.03
1890 2020-05-27 16:48:00+00:00 1000.02
1891 2020-05-27 16:49:00+00:00 1000.02
[1892 rows x 2 columns], 1000.0247878589546], [ timestamp capital
0 2020-06-02 22:08:00+00:00 1000
1 2020-06-02 22:09:00+00:00 1000
2 2020-06-02 22:10:00+00:00 999.925
3 2020-06-02 22:11:00+00:00 999.925
4 2020-06-02 22:12:00+00:00 999.925
... ... ...
2593 2020-06-04 17:23:00+00:00 999.7
2594 2020-06-04 17:24:00+00:00 999.7
2595 2020-06-04 17:25:00+00:00 999.7
2596 2020-06-04 17:26:00+00:00 999.7
2597 2020-06-04 17:27:00+00:00 999.7
[2598 rows x 2 columns], 999.6999999999999], [ timestamp capital
0 2020-05-27 16:49:00+00:00 1000
1 2020-05-27 16:50:00+00:00 1000
2 2020-05-27 16:51:00+00:00 1000
3 2020-05-27 16:52:00+00:00 1000
4 2020-05-27 16:53:00+00:00 1000
... ... ...
3765 2020-05-30 07:38:00+00:00 1000.56
3766 2020-05-30 07:39:00+00:00 1000.56
3767 2020-05-30 07:40:00+00:00 1000.56
3768 2020-05-30 07:41:00+00:00 1001.55
3769 2020-05-30 07:42:00+00:00 1001.55
[3770 rows x 2 columns], 1001.5513098187641], [ timestamp capital
0 2020-05-30 07:42:00+00:00 1000
1 2020-05-30 07:43:00+00:00 1000
2 2020-05-30 07:44:00+00:00 1000
3 2020-05-30 07:45:00+00:00 1000
4 2020-05-30 07:46:00+00:00 1000
... ... ...
5177 2020-06-02 22:04:00+00:00 998.021
5178 2020-06-02 22:05:00+00:00 998.021
5179 2020-06-02 22:06:00+00:00 998.021
5180 2020-06-02 22:07:00+00:00 1003.59
5181 2020-06-02 22:08:00+00:00 1003.59
[5182 rows x 2 columns], 1003.5854964926011]]
Expected output:
0
got here2
1
got here
2
got here
3
got here
4
got here