Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def gen_three_data(): ''' Generate 3 dictionaries with keys A and B ''' for i in range(3): yield { A: i + 1, B: (i +

def gen_three_data(): ''' Generate 3 dictionaries with keys A and B ''' for i in range(3): yield { "A": i + 1, "B": (i + 1) * 10, }

import pandas as pd

pd.DataFrame(data=gen_three_data())

import numpy as np def gen_some_data(n): ''' Generate n dictionaries with keys A, B and C ''' for i in range(n): yield { "A": i + 1, "B": (i + 1) * 10, "C": np.random.randn() }

import pandas as pd

pd.DataFrame(data=gen_some_data(10))

Question:

We need to get the data from the file assets/companies_small_set.data into a DataFrame. The problem is that the data on each line of the file is in either a JSON or Tab-separated values (TSV) format.

The JSON lines are in the correct format, they just need to be converted to native Python dicts.

The TSV lines need to be converted in to dicts that match the JSON format.

Write a generator gen_fixed_data that takes an iterator as an arguement. It should parse the values in the iterator and yield each value in the correct format: A dict with the keys:

  • company
  • catch_phrase
  • phone
  • timezone
  • client_count

import json

def gen_fix_data(data_iterator): # YOUR CODE HERE

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle PL SQL For Dummies

Authors: Michael Rosenblum, Paul Dorsey

1st Edition

0764599577, 978-0764599576

More Books

Students also viewed these Databases questions