docs/en/10-third-party/05-bi/18-Pandas.md
Pandas is the most popular data processing and analysis library in the Python programming language. Since its creation in 2008 by Wes McKinney, it has become an indispensable core tool in the field of data science. Designed specifically to address real-world data analysis tasks, Pandas makes handling structured data in Python exceptionally straightforward. Whether dealing with business reports, scientific research data, or conducting financial analysis, Pandas provides professional solutions. With its intuitive API and extensive functionality, Pandas significantly lowers the technical barrier to data processing, enabling users to focus more on uncovering the value within the data rather than getting bogged down in technical intricacies.
Through the Python connector of TDengine TSDB, Pandas supports TDengine TSDB data sources and provides capabilities for data presentation and analysis.
Prepare the following environment:
Pandas uses SQLAlchemy to connect to TDengine TSDB data sources, with the connection URL formatted as:
taos://[username]:[password]@[<host1>:<port1>]/[database_name]
Establishing Connection
{{#include docs/examples/python/conn_native_pandas.py:connect}}
The following describes how to perform write and query operations with the TDengine TSDB database by invoking Pandas interfaces in combination with SQLAlchemy. For detailed specifications of the Pandas interfaces, please refer to Pandas Api.
TDengine currently supports timestamp, number, character, and boolean types, and the corresponding type conversions with Fsqlalchemy.types are as follows:
| Sqlalchemy Types | TDengine TSDB DataType |
|---|---|
| sqltypes.Boolean | BOOL |
| sqltypes.TIMESTAMP | TIMESTAMP |
| sqltypes.Integer | INT |
| sqltypes.Integer | INT UNSIGNED |
| sqltypes.BigInteger | BIGINT |
| sqltypes.BigInteger | BIGINT UNSIGNED |
| sqltypes.FLOAT | FLOAT |
| sqltypes.FLOAT | DOUBLE |
| sqltypes.SmallInteger | TINYINT |
| sqltypes.SmallInteger | TINYINT UNSIGNED |
| sqltypes.SmallInteger | SMALLINT |
| sqltypes.SmallInteger | SMALLINT UNSIGNED |
| sqltypes.String | BINARY |
| sqltypes.String | VARCHAR |
| sqltypes.BINARY | VARBINARY |
| sqltypes.Unicode | NCHAR |
| sqltypes.JSON | JSON |
| sqltypes.BLOB | BLOB |
| sqltypes.BINARY | GEOMETRY |
Writing data using Pandas' to_sql method:
{{#include docs/examples/python/conn_native_pandas.py:pandas_to_sql_example}}
Querying using Pandas' read_sql method:
{{#include docs/examples/python/conn_native_pandas.py:pandas_read_sql_example}}
Reading table data using Pandas' read_sql_table method:
{{#include docs/examples/python/conn_native_pandas.py:pandas_read_sql_table_example}}