11(pandas)=
22# pandas
33
4- ``` {div}
5- :style: "float: right"
6- [{w=180px}](https://pandas.pydata.org/)
7- ```
8- ``` {div} .clearfix
9- ```
4+ :::{div} .float-right .text-right
5+ [ ![ pandas logo] ( https://pandas.pydata.org/static/img/pandas.svg ) {height=60px loading=lazy}] [ pandas ]
6+ <br >
7+ [ ![ pandas CI] ( https://img.shields.io/github/actions/workflow/status/crate/cratedb-examples/dataframe-pandas.yml?branch=main )] ( https://github.com/crate/cratedb-examples/actions/workflows/dataframe-pandas.yml )
8+ :::
9+ :::{div} .clearfix
10+ :::
1011
1112:::{rubric} About
1213:::
1516and manipulation tool, built on top of the Python programming language. It offers
1617data structures and operations for manipulating numerical tables and time series.
1718
18- :::{rubric} Data Model
19+ Pandas is built around data structures called Series and DataFrames. Data for these
20+ collections can be imported from various file formats such as comma-separated values,
21+ JSON, Parquet, SQL database tables or queries, and Microsoft Excel.
22+ A Series is a 1-dimensional data structure built on top of NumPy's array.
23+
24+ :::{rubric} Install
1925:::
20- - Pandas is built around data structures called Series and DataFrames. Data for these
21- collections can be imported from various file formats such as comma-separated values,
22- JSON, Parquet, SQL database tables or queries, and Microsoft Excel.
23- - A Series is a 1-dimensional data structure built on top of NumPy's array.
24- - Pandas includes support for time series, such as the ability to interpolate values
25- and filter using a range of timestamps.
26- - By default, a Pandas index is a series of integers ascending from 0, similar to the
27- indices of Python arrays. However, indices can use any NumPy data type, including
28- floating point, timestamps, or strings.
29- - Pandas supports hierarchical indices with multiple values per data point. An index
30- with this structure, called a "MultiIndex", allows a single DataFrame to represent
31- multiple dimensions, similar to a pivot table in Microsoft Excel. Each level of a
32- MultiIndex can be given a unique name.
3326
27+ ``` shell
28+ pip install pandas sqlalchemy-cratedb
29+ ```
3430
35- :::{rubric} Learn
31+ :::{rubric} Synopsis
3632:::
33+
34+ Write pandas dataframe to CrateDB.
35+
36+ ` example.py `
37+ ``` python
38+ import sqlalchemy as sa
39+ from sqlalchemy_cratedb import insert_bulk
40+
41+ CRATEDB_URI = " crate://crate:crate@localhost:4200"
42+ TABLE_NAME = " example"
43+
44+ df = makeTimeDataFrame(rows = 500_000 , freq = " s" )
45+ engine = sa.create_engine(CRATEDB_URI )
46+ df.to_sql(
47+ name = TABLE_NAME ,
48+ con = engine,
49+ if_exists = " replace" ,
50+ index = False ,
51+ chunksize = 20_000 ,
52+ method = insert_bulk,
53+ )
54+ ```
55+
56+ :::{rubric} Quickstart example
57+ :::
58+
59+ Create the file ` example.py ` including the synopsis code shared above.
60+ Complete the example by using the ` makeTimeDataFrame() ` function.
61+
62+ :::{literalinclude} ../pandas/makeTimeDataFrame.py
63+ :::
64+
65+ :::{include} /connect/_ cratedb.md
66+ :::
67+ ``` shell
68+ pip install pandas sqlalchemy-cratedb
69+ python example.py
70+ ```
71+
72+ :::{rubric} Full example
73+ :::
74+
75+ :::{card}
76+ :link : https://github.com/crate/cratedb-examples/tree/main/by-dataframe/pandas
77+ :link-type: url
78+ {material-regular}` play_arrow;2em `
79+ Connect to CrateDB and CrateDB Cloud using pandas.
80+ +++
81+ Includes basic examples of how to use pandas with CrateDB.
82+ :::
83+
84+ :::{rubric} Guides
85+ :::
86+
87+ - {ref}` pandas-efficient-import `
3788- {ref}` pandas-tutorial-start `
3889- {ref}` pandas-tutorial-jupyter `
39- - {ref}` arrow-import-parquet `
40- - {ref}` pandas-bulk-import `
41- - See also: {ref}` dask-bulk-import `
42- - See also: [ Efficient batch/bulk INSERT operations with pandas, Dask, and SQLAlchemy]
4390
44- :::{rubric} Code examples
91+ :::{rubric} Related sections
4592:::
46- - [ pandas code examples]
93+
94+ - {ref}` Efficient batch/bulk INSERT operations for pandas, Dask, and Polars <sqlalchemy-cratedb:dataframe> `
95+ - {ref}` arrow-import-parquet `
4796
4897
4998:::{toctree}
@@ -55,6 +104,4 @@ Efficient ingest <efficient-ingest>
55104:::
56105
57106
58- [ Efficient batch/bulk INSERT operations with pandas, Dask, and SQLAlchemy ] : https://cratedb.com/docs/python/en/latest/by-example/sqlalchemy/dataframe.html
59107[ pandas ] : https://pandas.pydata.org/
60- [ pandas code examples ] : https://github.com/crate/cratedb-examples/tree/main/by-dataframe/pandas
0 commit comments