Make it easier to manually create DataFrames
See original GitHub issueWe often need to create Minimal Complete Verifiable Examples with Dask DataFrames for blog posts, questions, etc.
Here’s how Dask allows you to make these examples currently:
import pandas as pd
pandas_df = pd.DataFrame(
{"num1": [1, 2, 3, 4], "num2": [7, 8, 9, 10]},
)
df = dd.from_pandas(pandas_df, npartitions=2)
This is confusing for some users. They are not sure why pandas needs to be imported and can struggle making the pandas => Dask connection.
The following syntax would make the MCVEs shorter and easier to understand:
import dask.dataframe as dd
ddf = dd.DataFrame(
{"num1": [1, 2, 3, 4], "num2": [7, 8, 9, 10]},
npartitions=2,
)
Let me know if this suggestion sounds good and I can submit a PR. Or perhaps there is already a way to directly create a Dask DataFrame in a similar manner?
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Different ways to create Pandas Dataframe - GeeksforGeeks
Pandas DataFrame can be created in multiple ways. Let's discuss different ways to create a DataFrame one by one.
Read more >15 ways to create a Pandas DataFrame - Towards Data Science
Method 0 — Initialize Blank dataframe and keep adding records. · Method 1 — using numpy array in the DataFrame constructor. · Method...
Read more >Pandas - create dataframe manually and insert values
You can either initialize dataframe with data using. df = pd.DataFrame(columns=["A", "B"], data=[[5,np.nan]]) ,. or use set_value method (which is much ...
Read more >How to Create DataFrame in R (with Examples) - Data to Fish
Let's start with a simple example, where the dataset is: ... Once you run the above code in R, you'll get this simple...
Read more >Create Pandas DataFrame With Examples
One of the easiest ways to create a pandas DataFrame is by using its constructor. DataFrame constructor takes several optional params that are...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks @MrPowers, I think this is a reasonable request but wouldn’t want to see us point users directly to the
dd.DataFrame
constructor as it’s a fairly low-level class constructor and we prefer to route users towards more friendly methods likedd.read_parquet
,dd.from_delayed
, etc.That said, adding a new
dd.from_dict
method similar to pandas’pd.from_dict
seems like a nice way to accomplish what you’re after while also sticking with an existing DataFrame API. Adding this new method would be my personal preference@jrbourbeau -
dd.from_dict
sounds like a great approach to me. I’ll prep a PR. Thanks!