@@ -33,7 +33,19 @@ class DataFrame(NDFrame):
33
33
34
34
@property
35
35
def shape (self ) -> tuple [int , int ]:
36
- """Return a tuple representing the dimensionality of the DataFrame."""
36
+ """
37
+ Return a tuple representing the dimensionality of the DataFrame.
38
+
39
+ **Examples:**
40
+
41
+ >>> import bigframes.pandas as bpd
42
+ >>> bpd.options.display.progress_bar = None
43
+
44
+ >>> df = bpd.DataFrame({'col1': [1, 2, 3],
45
+ ... 'col2': [4, 5, 6]})
46
+ >>> df.shape
47
+ (3, 2)
48
+ """
37
49
raise NotImplementedError (constants .ABSTRACT_METHOD_ERROR_MESSAGE )
38
50
39
51
@property
@@ -44,21 +56,31 @@ def axes(self) -> list:
44
56
It has the row axis labels and column axis labels as the only members.
45
57
They are returned in that order.
46
58
47
- Examples
59
+ ** Examples:**
48
60
49
- .. code-block::
61
+ >>> import bigframes.pandas as bpd
62
+ >>> bpd.options.display.progress_bar = None
50
63
51
- df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
52
- df.axes
53
- [RangeIndex(start=0, stop=2, step=1), Index(['col1', 'col2'],
54
- dtype='object')]
64
+ >>> df = bpd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
65
+ >>> df.axes[1:]
66
+ [Index(['col1', 'col2'], dtype='object')]
55
67
"""
56
68
return [self .index , self .columns ]
57
69
58
70
@property
59
71
def values (self ) -> np .ndarray :
60
72
"""Return the values of DataFrame in the form of a NumPy array.
61
73
74
+ **Examples:**
75
+
76
+ >>> import bigframes.pandas as bpd
77
+ >>> bpd.options.display.progress_bar = None
78
+
79
+ >>> df = bpd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
80
+ >>> df.values
81
+ array([[1, 3],
82
+ [2, 4]], dtype=object)
83
+
62
84
Args:
63
85
dytype (default None):
64
86
The dtype to pass to `numpy.asarray()`.
@@ -76,6 +98,16 @@ def to_numpy(self, dtype=None, copy=False, na_value=None, **kwargs) -> np.ndarra
76
98
"""
77
99
Convert the DataFrame to a NumPy array.
78
100
101
+ **Examples:**
102
+
103
+ >>> import bigframes.pandas as bpd
104
+ >>> bpd.options.display.progress_bar = None
105
+
106
+ >>> df = bpd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
107
+ >>> df.to_numpy()
108
+ array([[1, 3],
109
+ [2, 4]], dtype=object)
110
+
79
111
Args:
80
112
dtype (None):
81
113
The dtype to pass to `numpy.asarray()`.
@@ -101,6 +133,15 @@ def to_gbq(
101
133
) -> None :
102
134
"""Write a DataFrame to a BigQuery table.
103
135
136
+ **Examples:**
137
+
138
+ >>> import bigframes.pandas as bpd
139
+ >>> bpd.options.display.progress_bar = None
140
+
141
+ >>> df = bpd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
142
+ >>> # destination_table = PROJECT_ID + "." + DATASET_ID + "." + TABLE_NAME
143
+ >>> df.to_gbq("bigframes-dev.birds.test-numbers", if_exists="replace")
144
+
104
145
Args:
105
146
destination_table (str):
106
147
Name of table to be written, in the form ``dataset.tablename``
@@ -137,6 +178,15 @@ def to_parquet(
137
178
This function writes the dataframe as a `parquet file
138
179
<https://parquet.apache.org/>`_ to Cloud Storage.
139
180
181
+ **Examples:**
182
+
183
+ >>> import bigframes.pandas as bpd
184
+ >>> bpd.options.display.progress_bar = None
185
+
186
+ >>> df = bpd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
187
+ >>> gcs_bucket = "gs://bigframes-dev-testing/sample_parquet*.parquet"
188
+ >>> df.to_parquet(path=gcs_bucket)
189
+
140
190
Args:
141
191
path (str):
142
192
Destination URI(s) of Cloud Storage files(s) to store the extracted dataframe
@@ -171,6 +221,35 @@ def to_dict(
171
221
The type of the key-value pairs can be customized with the parameters
172
222
(see below).
173
223
224
+ **Examples:**
225
+
226
+ >>> import bigframes.pandas as bpd
227
+ >>> bpd.options.display.progress_bar = None
228
+
229
+ >>> df = bpd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
230
+ >>> df.to_dict()
231
+ {'col1': {0: 1, 1: 2}, 'col2': {0: 3, 1: 4}}
232
+
233
+ You can specify the return orientation.
234
+
235
+ >>> df.to_dict('series')
236
+ {'col1': 0 1
237
+ 1 2
238
+ Name: col1, dtype: Int64,
239
+ 'col2': 0 3
240
+ 1 4
241
+ Name: col2, dtype: Int64}
242
+
243
+ >>> df.to_dict('split')
244
+ {'index': [0, 1], 'columns': ['col1', 'col2'], 'data': [[1, 3], [2, 4]]}
245
+
246
+ >>> df.to_dict("tight")
247
+ {'index': [0, 1],
248
+ 'columns': ['col1', 'col2'],
249
+ 'data': [[1, 3], [2, 4]],
250
+ 'index_names': [None],
251
+ 'column_names': [None]}
252
+
174
253
Args:
175
254
orient (str {'dict', 'list', 'series', 'split', 'tight', 'records', 'index'}):
176
255
Determines the type of the values of the dictionary.
@@ -213,6 +292,15 @@ def to_excel(self, excel_writer, sheet_name: str = "Sheet1", **kwargs) -> None:
213
292
Note that creating an `ExcelWriter` object with a file name that already
214
293
exists will result in the contents of the existing file being erased.
215
294
295
+ **Examples:**
296
+
297
+ >>> import bigframes.pandas as bpd
298
+ >>> import tempfile
299
+ >>> bpd.options.display.progress_bar = None
300
+
301
+ >>> df = bpd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
302
+ >>> df.to_excel(tempfile.TemporaryFile())
303
+
216
304
Args:
217
305
excel_writer (path-like, file-like, or ExcelWriter object):
218
306
File path or existing ExcelWriter.
@@ -231,6 +319,23 @@ def to_latex(
231
319
into a main LaTeX document or read from an external file
232
320
with ``\input{{table.tex}}``.
233
321
322
+ **Examples:**
323
+
324
+ >>> import bigframes.pandas as bpd
325
+ >>> bpd.options.display.progress_bar = None
326
+
327
+ >>> df = bpd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
328
+ >>> print(df.to_latex())
329
+ \begin{tabular}{lrr}
330
+ \toprule
331
+ & col1 & col2 \\
332
+ \midrule
333
+ 0 & 1 & 3 \\
334
+ 1 & 2 & 4 \\
335
+ \bottomrule
336
+ \end{tabular}
337
+ <BLANKLINE>
338
+
234
339
Args:
235
340
buf (str, Path or StringIO-like, optional, default None):
236
341
Buffer to write to. If None, the output is returned as a string.
@@ -253,6 +358,16 @@ def to_records(
253
358
Index will be included as the first field of the record array if
254
359
requested.
255
360
361
+ **Examples:**
362
+
363
+ >>> import bigframes.pandas as bpd
364
+ >>> bpd.options.display.progress_bar = None
365
+
366
+ >>> df = bpd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
367
+ >>> df.to_records()
368
+ rec.array([(0, 1, 3), (1, 2, 4)],
369
+ dtype=[('index', 'O'), ('col1', 'O'), ('col2', 'O')])
370
+
256
371
Args:
257
372
index (bool, default True):
258
373
Include index in resulting record array, stored in 'index'
@@ -298,6 +413,17 @@ def to_string(
298
413
):
299
414
"""Render a DataFrame to a console-friendly tabular output.
300
415
416
+ **Examples:**
417
+
418
+ >>> import bigframes.pandas as bpd
419
+ >>> bpd.options.display.progress_bar = None
420
+
421
+ >>> df = bpd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
422
+ >>> print(df.to_string())
423
+ col1 col2
424
+ 0 1 3
425
+ 1 2 4
426
+
301
427
Args:
302
428
buf (str, Path or StringIO-like, optional, default None):
303
429
Buffer to write to. If None, the output is returned as a string.
@@ -363,6 +489,18 @@ def to_markdown(
363
489
):
364
490
"""Print DataFrame in Markdown-friendly format.
365
491
492
+ **Examples:**
493
+
494
+ >>> import bigframes.pandas as bpd
495
+ >>> bpd.options.display.progress_bar = None
496
+
497
+ >>> df = bpd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
498
+ >>> print(df.to_markdown())
499
+ | | col1 | col2 |
500
+ |---:|-------:|-------:|
501
+ | 0 | 1 | 3 |
502
+ | 1 | 2 | 4 |
503
+
366
504
Args:
367
505
buf (str, Path or StringIO-like, optional, default None):
368
506
Buffer to write to. If None, the output is returned as a string.
@@ -371,7 +509,7 @@ def to_markdown(
371
509
index (bool, optional, default True):
372
510
Add index (row) labels.
373
511
**kwargs
374
- These parameters will be passed to `tabulate <https://pypi.org/project/tabulate>`_.
512
+ These parameters will be passed to `tabulate <https://pypi.org/project/tabulate>`_.
375
513
376
514
Returns:
377
515
DataFrame in Markdown-friendly format.
@@ -381,6 +519,15 @@ def to_markdown(
381
519
def to_pickle (self , path , ** kwargs ) -> None :
382
520
"""Pickle (serialize) object to file.
383
521
522
+ **Examples:**
523
+
524
+ >>> import bigframes.pandas as bpd
525
+ >>> bpd.options.display.progress_bar = None
526
+
527
+ >>> df = bpd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
528
+ >>> gcs_bucket = "gs://bigframes-dev-testing/sample_pickle_gcs.pkl"
529
+ >>> df.to_pickle(path=gcs_bucket)
530
+
384
531
Args:
385
532
path (str):
386
533
File path where the pickled object will be stored.
@@ -391,6 +538,15 @@ def to_orc(self, path=None, **kwargs) -> bytes | None:
391
538
"""
392
539
Write a DataFrame to the ORC format.
393
540
541
+ **Examples:**
542
+
543
+ >>> import bigframes.pandas as bpd
544
+ >>> bpd.options.display.progress_bar = None
545
+
546
+ >>> df = bpd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
547
+ >>> import tempfile
548
+ >>> df.to_orc(tempfile.TemporaryFile())
549
+
394
550
Args:
395
551
path (str, file-like object or None, default None):
396
552
If a string, it will be used as Root Directory path
0 commit comments