-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Add doc-string examples for pd.read_sql using custom parse_dates arg values #38475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
99d5e5b
46ffa21
602040f
98eecb1
82ff533
7409ccb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -478,6 +478,41 @@ def read_sql( | |
------- | ||
DataFrame or Iterator[DataFrame] | ||
|
||
Examples | ||
-------- | ||
Read data from SQL via either a SQL tablename or a SQL query | ||
|
||
>>> pd.read_sql('table_name', 'postgres:///db_name') # doctest:+SKIP | ||
|
||
>>> pd.read_sql('SELECT * FROM table_name', 'postgres:///db_name') # doctest:+SKIP | ||
|
||
Apply dateparsing to columns through the "parse_dates" argument | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double backticks around There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
>>> pd.read_sql('table_name', | ||
... 'postgres:///db_name', | ||
... parse_dates=["date_column"]) # doctest:+SKIP | ||
|
||
The "parse_dates" argument calls pd.to_datetime on the provided columns. Custom | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double backticks around There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
argument values for applying pd.to_datetime on a column are specified via a | ||
dictionary format: | ||
1. Ignore errors while parsing the values of "date_column" | ||
|
||
>>> pd.read_sql('table_name', | ||
... 'postgres:///db_name', | ||
... parse_dates={"date_column": {"errors": "ignore"}) # doctest:+SKIP | ||
|
||
2. Apply a dayfirst dateparsing order on the values of "date_column" | ||
|
||
>>> pd.read_sql('table_name', | ||
... 'postgres:///db_name', | ||
... parse_dates={"date_column": {"dayfirst": True}) # doctest:+SKIP | ||
|
||
3. Apply custom formatting when dateparsing the values of "date_column" | ||
|
||
>>> pd.read_sql('table_name', | ||
... 'postgres:///db_name', | ||
... parse_dates={"date_column": {"format": "%d/%m/%Y"}) # doctest:+SKIP | ||
|
||
See Also | ||
-------- | ||
read_sql_table : Read SQL database table into a DataFrame. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the examples can demonstrate connecting to a sqlite db so we don't have to skip all these doctests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done