@@ -478,6 +478,41 @@ def read_sql(
478
478
-------
479
479
DataFrame or Iterator[DataFrame]
480
480
481
+ Examples
482
+ --------
483
+ Read data from SQL via either a SQL tablename or a SQL query
484
+
485
+ >>> pd.read_sql('table_name', 'postgres:///db_name') # doctest:+SKIP
486
+
487
+ >>> pd.read_sql('SELECT * FROM table_name', 'postgres:///db_name') # doctest:+SKIP
488
+
489
+ Apply dateparsing to columns through the "parse_dates" argument
490
+
491
+ >>> pd.read_sql('table_name',
492
+ ... 'postgres:///db_name',
493
+ ... parse_dates=["date_column"]) # doctest:+SKIP
494
+
495
+ The "parse_dates" argument calls pd.to_datetime on the provided columns. Custom
496
+ argument values for applying pd.to_datetime on a column are specified via a
497
+ dictionary format:
498
+ 1. Ignore errors while parsing the values of "date_column"
499
+
500
+ >>> pd.read_sql('table_name',
501
+ ... 'postgres:///db_name',
502
+ ... parse_dates={"date_column": {"errors": "ignore"}) # doctest:+SKIP
503
+
504
+ 2. Apply a dayfirst dateparsing order on the values of "date_column"
505
+
506
+ >>> pd.read_sql('table_name',
507
+ ... 'postgres:///db_name',
508
+ ... parse_dates={"date_column": {"dayfirst": True}) # doctest:+SKIP
509
+
510
+ 3. Apply custom formatting when dateparsing the values of "date_column"
511
+
512
+ >>> pd.read_sql('table_name',
513
+ ... 'postgres:///db_name',
514
+ ... parse_dates={"date_column": {"format": "%d/%m/%Y"}) # doctest:+SKIP
515
+
481
516
See Also
482
517
--------
483
518
read_sql_table : Read SQL database table into a DataFrame.
0 commit comments