(self, key)
return func_lines
Generate code lines to add new column to DF
Generate code lines to add new column to DF
Generate code lines to add new column to DF
def df_add_column_codelines(self, key):
    """Generate code lines to add new column to DF"""
    func_lines = df_set_column_index_codelines(self)  # provide res_index = ...

    results = []
    for i, col in enumerate(self.columns):
        col_loc = self.column_loc[col]
        type_id, col_id = col_loc.type_id, col_loc.col_id
        res_data = f'res_data_{i}'
        func_lines += [
            f'  data_{i} = self._data[{type_id}][{col_id}]',
            f'  {res_data} = data_{i}',
        ]
        results.append((col, res_data))

    res_data = 'new_res_data'
    literal_key = key.literal_value
    func_lines += [f'  {res_data} = value']
    results.append((literal_key, res_data))

    data = ', '.join(f'"{col}": {data}' for col, data in results)
    func_lines += [f'  return pandas.DataFrame({{{data}}}, index=res_index)']

    return func_lines
def df_add_column_codelines ( self , key ) : func_lines = df_set_column_index_codelines ( self ) # provide res_index = ... results = [ ] for i , col in enumerate ( self . columns ) : col_loc = self . column_loc [ col ] type_id , col_id = col_loc . type_id , col_loc . col_id res_data = f'res_data_{i}' func_lines += [ f'  data_{i} = self._data[{type_id}][{col_id}]' , f'  {res_data} = data_{i}' , ] results . append ( ( col , res_data ) ) res_data = 'new_res_data' literal_key = key . literal_value func_lines += [ f'  {res_data} = value' ] results . append ( ( literal_key , res_data ) ) data = ', ' . join ( f'"{col}": {data}' for col , data in results ) func_lines += [ f'  return pandas.DataFrame({{{data}}}, index=res_index)' ] return func_lines