Modified the function to pass data into a dictionary, then convert to dataframe