Snippet
1 Upvote

Creating a Pandas DataFrame from a Python Generator

Python - Import and Export

pandas - dataframe - generator

In this example we create a dataframe from a Python generator that takes numbers from 1 to 10 and also returns the square of those numbers.
import pandas
generator = ((i,i**2) for i in range(1,11))
df = pd.DataFrame(generator,columns=['number','number_squared'])
df.head(10)
Creating a Pandas DataFrame from a Python Generator

By analyseup - Last Updated Sept. 22, 2021, 4:21 p.m.

Comments
Related Snippets
Snippet
Upvotes
Creator