This is how my dataframe looks:
FULL_NAME ARGUMENT DEF_VALS TYPE
function1 f1_arg1 NAN NoneType
function1 f1_arg2 NAN NAN
function1 f1_arg3 NAN NAN
function2 f2_arg1 0 int
function3 f3_arg1 True bool
function3 f3_arg2 'something' str
Here's how that data can be reproduced:
import pandas
D = {'FULL_NAME': ['function1', 'function1', 'function1', 'function2', 'function3', 'function3'], 'ARGUMENT': ['f1_arg1', 'f1_arg2', 'f1_arg3', 'f2_arg1', 'f3_arg1', 'f3_arg2'], 'DEF_VAL': [float('nan'), float('nan'), float('nan'), 0, True, 'something'], 'TYPE': ['NoneType', float('nan'), float('nan'), 'int', 'bool', 'str']}
dataframe = pandas.DataFrame(D)
Using this dataframe I need to somehow write the following info into a text file:
a1=None
a2=
a3=
function1(f1_arg1=a1, f1_arg2=a2, f1_arg3=a3)
a1=0
function2(f2_arg1=a1)
a1=True
a2='something'
function3(f3_arg1=a1, f3_arg2=a2)
The conditions for writing are the following:
a{i} should be equal to an argument default value unless the default value is NAN and its type is NAN (in this case it should be followed by the '=' sign). If the default value of the argument is NAN but the type is NoneType then a{i} must be None.
All the values in the columns 'FULL_NAME' and 'ARGUMENT' are strings.
There is also one more condition that complicates everything immensely: if the value of one of the arguments is equal to some special value (special_value) then it should not be included into the function signature. For example, if we have function g(W, r, dim, fix=False, r=0) where 'W' is the special argument, then what should be written to the text file for this function is this:
a1=
a2=
a3=False
a4=0
g(r=a1, dim=a2, fix=a3, r=a4)
Where 'a1' corresponds to 'r', 'a2' corresponds to 'dim' etc and 'W' is ignored.
How could I get that output by using pandas? Is it possible at all?
EDIT:
In more simple terms, having this dataframe:
FULL_NAME ARGUMENT DEF_VALS TYPE
function1 f1_arg1 NAN NoneType
function1 f1_arg2 NAN NAN
function1 f1_arg3 NAN NAN
function2 f2_arg1 0 int
function3 f3_arg1 True bool
function3 f3_arg2 'something' str
and taking into account the above-mentioned conditions I would like to make it look like this:
function args
function1(f1_arg1=a1, f1_arg2=a2, f1_arg3=a3) ['a1=None', 'a2=', 'a3=']
function2(f2_arg1=a1) ['a1=0']
function3(f3_arg1=a1, f3_arg2=a2) ['a1=True', 'a2=something']