• Sreeram Venkatesh
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
rows = [
    {'Name': 'Name 1', 'Date': '06-Aug', 'Jan': 150, 'Feb': None, 'March': None, 'Apr': None, 'May': None},
    {'Name': 'Name 2', 'Date': '07-Aug', 'Jan': None, 'Feb': 100, 'March': 110, 'Apr': None, 'May': None},
    {'Name': 'Name 3', 'Date': '07-Aug', 'Jan': None, 'Feb': None, 'March': 400, 'Apr': 500, 'May': None},
]

def get_formatted_data(rows):
    data = []

    # For each row of rows
    for row in rows:

        # Loop through each key, value pair of row
        for key, val in row.items():
            data_dict = {
                'Name': row['Name'],
                'Date': row['Date']
            }
            if key not in ('Name', 'Date') and val:
                data_dict['Month'] = key
                data_dict['Rate'] = val
                data.append(data_dict)
    return data
rows = [
    {'Name': 'Name 1', 'Date': '06-Aug', 'Jan': 150, 'Feb': None, 'March': None, 'Apr': None, 'May': None},
    {'Name': 'Name 2', 'Date': '07-Aug', 'Jan': None, 'Feb': 100, 'March': 110, 'Apr': None, 'May': None},
    {'Name': 'Name 3', 'Date': '07-Aug', 'Jan': None, 'Feb': None, 'March': 400, 'Apr': 500, 'May': None},
]

def get_formatted_data(rows):
    data = []

    # For each row of rows
    for row in rows:

        # Loop through each key, value pair of row
        for key, val in row.items():
            data_dict = {
                'Name': row['Name'],
                'Date': row['Date']
            }
            if key not in ('Name', 'Date') and val:
                data_dict['Month'] = key
                data_dict['Rate'] = val
                data.append(data_dict)
    return data