DataFrame-like Expr Collection. The constructor takes the expression that represents the query as input. The class is not meant to be instantiated directly. Instead, use one of the IO connectors from Dask.
| 2687 | |
| 2688 | |
| 2689 | class DataFrame(FrameBase): |
| 2690 | """DataFrame-like Expr Collection. |
| 2691 | |
| 2692 | The constructor takes the expression that represents the query as input. The class |
| 2693 | is not meant to be instantiated directly. Instead, use one of the IO connectors from |
| 2694 | Dask. |
| 2695 | """ |
| 2696 | |
| 2697 | _accessors: ClassVar[set[str]] = set() |
| 2698 | _partition_type = pd.DataFrame |
| 2699 | |
| 2700 | @property |
| 2701 | def shape(self): |
| 2702 | return self.size // max(len(self.columns), 1), len(self.columns) |
| 2703 | |
| 2704 | @property |
| 2705 | def ndim(self): |
| 2706 | """Return dimensionality""" |
| 2707 | return 2 |
| 2708 | |
| 2709 | @property |
| 2710 | def empty(self): |
| 2711 | # __getattr__ will be called after we raise this, so we'll raise it again from there |
| 2712 | raise AttributeNotImplementedError( |
| 2713 | "Checking whether a Dask DataFrame has any rows may be expensive. " |
| 2714 | "However, checking the number of columns is fast. " |
| 2715 | "Depending on which of these results you need, use either " |
| 2716 | "`len(df.index) == 0` or `len(df.columns) == 0`" |
| 2717 | ) |
| 2718 | |
| 2719 | @derived_from(pd.DataFrame) |
| 2720 | def items(self): |
| 2721 | for i, name in enumerate(self.columns): |
| 2722 | yield (name, self.iloc[:, i]) |
| 2723 | |
| 2724 | @property |
| 2725 | def axes(self): |
| 2726 | return [self.index, self.columns] |
| 2727 | |
| 2728 | def __contains__(self, key): |
| 2729 | return key in self._meta |
| 2730 | |
| 2731 | def __iter__(self): |
| 2732 | return iter(self._meta) |
| 2733 | |
| 2734 | def __dataframe__(self, *args, **kwargs): |
| 2735 | from dask.dataframe.dask_expr._interchange import DaskDataFrameInterchange |
| 2736 | |
| 2737 | return DaskDataFrameInterchange(self) |
| 2738 | |
| 2739 | @derived_from(pd.DataFrame) |
| 2740 | def iterrows(self): |
| 2741 | frame = self.optimize() |
| 2742 | for i in range(self.npartitions): |
| 2743 | df = frame.get_partition(i).compute() |
| 2744 | yield from df.iterrows() |
| 2745 | |
| 2746 | @derived_from(pd.DataFrame) |