Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started