question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make it easier to manually create DataFrames

See original GitHub issue

We 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:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
jrbourbeaucommented, May 2, 2022

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 like dd.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

3reactions
MrPowerscommented, May 2, 2022

@jrbourbeau - dd.from_dict sounds like a great approach to me. I’ll prep a PR. Thanks!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found