Can anyone tell me what's wrong in this Qlik Sense expression - if-statement

LOAD
if(Year(max(FISCAL_YEAR))=Year(Today()),
Year(max(FINANCIAL_YEAR))) as Curr_FY,
if(Year(max(FISCAL_YEAR))=Year(Today()),
Year(today()-1)) as Prev_FY
Resident [data_table];
Let Current_FY = '=Curr_FY';
Let Last_FY = '=Prev_FY';
I want to create Dynamic variable for current FISCAL_YEAR and last FISCAL_YEAR

If the table contains only a single value for Curr_FY and Prev_FY then you can use peek script function to get the value in a variable
Let Current_FY = peek('Curr_FY');
Let Last_FY = peek('Prev_FY');
Bear in mind that if there are multiple values then peek will return the last loaded value

Related

How to convert list into DataFrame in Python (Binance Futures API)

Using Binance Futures API I am trying to get a proper form of my position regarding cryptocurrencies.
Using the code
from binance_f import RequestClient
request_client = RequestClient(api_key= my_key, secret_key=my_secet_key)
result = request_client.get_position()
I get the following result
[{"symbol":"BTCUSDT","positionAmt":"0.000","entryPrice":"0.00000","markPrice":"5455.13008723","unRealizedProfit":"0.00000000","liquidationPrice":"0","leverage":"20","maxNotionalValue":"5000000","marginType":"cross","isolatedMargin":"0.00000000","isAutoAddMargin":"false"}]
The type command indicates it is a list, however adding at the end of the code print(result) yields:
[<binance_f.model.position.Position object at 0x1135cb670>]
Which is baffling because it seems not to be the list (in fact, debugging it indicates object of type Position). Using PrintMix.print_data(result) yields:
data number 0 :
entryPrice:0.0
isAutoAddMargin:True
isolatedMargin:0.0
json_parse:<function Position.json_parse at 0x1165af820>
leverage:20.0
liquidationPrice:0.0
marginType:cross
markPrice:5442.28502271
maxNotionalValue:5000000.0
positionAmt:0.0
symbol:BTCUSDT
unrealizedProfit:0.0
Now it seems like a JSON format... But it is a list. I am confused - any ideas how I can convert result to a proper DataFrame? So that columns are Symbol, PositionAmt, entryPrice, etc.
Thanks!
Your main question remains as you wrote on the header you should not be confused. In your case you have a list of Position object, you can see the structure of Position in the GitHub of this library
Anyway to answer the question please use the following:
df = pd.DataFrame([t.__dict__ for t in result])
For more options and information please read the great answers on this question
Good Luck!
you can use that
df = pd.DataFrame([t.__dict__ for t in result])
klines=df.values.tolist()
open = [float(entry[1]) for entry in klines]
high = [float(entry[2]) for entry in klines]
low = [float(entry[3]) for entry in klines]
close = [float(entry[4]) for entry in klines]

Keeping an index with flatMap in Swift

This is a follow-up to this question:
flatMap and `Ambiguous reference to member` error
There I am using the following code to convert an array of Records to an array of Persons:
let records = // load file from bundle
let persons = records.flatMap(Person.init)
Since this conversion can take some time for big files, I would like to monitor an index to feed into a progress indicator.
Is this possible with this flatMap construction? One possibility I thought of would be to send a notification in the init function, but I am thinking counting the records is also possible from within flatMap ?
Yup! Use enumerated().
let records = // load file from bundle
let persons = records.enumerated().flatMap { index, record in
print(index)
return Person(record)
}

Scala. foreach in one element Lists of Dates

I want to create a function that works on a single date or over a period of time. For that I make a list of strings like this:
import com.github.nscala_time.time.Imports._
val fromDate = "2015-10-15".toLocalDate
val toDate = "2015-10-15".toLocalDate
val days = Iterator.iterate(fromDate)(_ + 1.day).takeWhile(_ <= toDate).map(_.toString)
Now I want to access days content:
scala> days.foreach(println)
2015-10-15
scala> days.foreach(day => println(day))
With the first foreach I get the only element in days list, but with the second I get nothing. This is just a sample, but I need to use the 2nd form, because I need to use day value inside the function.
If I use a range both methods work like they are supposed to...
Anyone knows why this behaviour?
Thanks in advance!
P.D. I don't want to use another method to create the list of strings (unless I can't find a solution for this)
Second function works in same way as first.
You've created Iterator object, which you can iterate only once.
To be able use it any amount of times just convert you iterator to list.
val daysL = days.toList

smarty name of variable dynamic

I'm studying smarty for about two months and I find myself be in front of a problem.
I am creating a dynamic menu that reads the configuration from a file called submenu.conf in this file are:
tot_sub_menu_2 = "2"
text_sub_menu_2_1 = "Home"
text_sub_menu_2_2 = "about"
tpl file in my application I wish he would create the menu dynamically in this way:
{for $foo=1 to #tot_sub_menu_2#}
<li>{#text_sub_menu_2_.{$foo}}</li>
{/for}
I would like to take a dynamic parameter text_sub_menu_2_1 the second loop becomes text_sub_menu_2_2 etc.
someone knows how to help me?
I have not tested but you can try using {counter}
{for $foo=1 to #tot_sub_menu_2#}
{* initialize the count *}
{counter start=0 skip=1}
<li>{#text_sub_menu_2_.{counter}}</li>
Otherwise you can make use of the #iteration property. See http://www.smarty.net/docs/en/language.function.foreach.tpl#foreach.property.iteration
iteration contains the current loop iteration and always starts at
one, unlike index. It is incremented by one on each iteration.
{foreach from=$new_products item='product' name='newProducts'}
// Do somthing
//Here i want to increment {$count} if it's lower than 3 or set to 1 if higher than 3
{if $product#iteration <= 3}{$count = $product#iteration}{else}{$count = 1}{/if}
{/foreach}

How do I loop through a list of stock tickers in Matlab?

This is the current code I'm attempting to use in order to loop through a "list" of tickers to load the corresponding file. However, Matlab doesn't seem to like to accept separate strings. I'm not quite sure how Matlab functions yet. However, it is clear that it does not handle text as easily as Python.
Stocks = {'JPM','KO','GOOG','PG'};
for Stock = Stocks;
stockData.(Stock) = load(Stock '.csv');
end
Your syntax is invalid. I don't know what stockData is, and what you want to assign to it, but here's a loop that iterates through the cell array Stocks and loads each file in turn:
Stocks = {'JPM','KO','GOOG','PG'};
for i = 1:length(Stocks);
load([Stocks{i}, '.csv'])
end
You can keep going from here.