Leaving out the lead-up and data to the following because it looks like an error in how the list comprehension is written. It is meant to cycle through a list l
of pandas DataFrame
s and Series
, and label them based on whether they are two dimensional (both index and columns) or one dimensional (index only). Why the error (even if a close the line-break)?
[pd.DataFrame(A, index=labels, columns=labels) for A in l
if type(A) is pd.DataFrame else pd.Series(A, index=labels)]
results in
if type(A) is pd.DataFrame else pd.Series(A, index=tickers)]
^
SyntaxError: invalid syntax