# Pandas-NoSQL
__Pandas-NoSQL adds read and write capabilities to pandas for several nosql databases__
---
Pandas read and write methods for:
* MongoDB
* Elasticsearch
* Redis
* Apache Cassandra
The dependencies used for the functions are:
* pymongo by MongoDB
* elasticsearch by Elastic
* redis-py by Redis
* cassandra-driver by DataStax
---
## Installation
```bash
$ pip install pandas-nosql
```
---
## Documentation
### MongoDB
```python
# Read a MongoDB collection into a DataFrame
# Defaults: host='localhost' port=27017
# For nested collections use normalize=True
import pandas as pd
import pandas_nosql
df = pd.read_mongo(
database = 'test_db',
collection = 'test_col',
normalize = True,
host = 'localhost',
port = 27017
)
# Write DataFrame to MongoDB collection
# modify_colletion parameter is to help prevent accidental overwrites
df.to_mongo(
database = 'test_db',
collection = 'test_col2',
mode = 'a',
host = 'localhost',
port = 27017
)
```
### Elasticsearch
```python
import pandas as pd
import pandas_nosql
# Read an Elastic index into a DataFrame
# To Access localhost:
# * hosts='https://localhost:9200'
# * verify_certs=False
# If "xpack.security.enabled: false" use http instead
# To split out _source use split_source=True
elastic_cols = ('make', 'model', 'purchase_date', 'miles')
df = pd.read_elastic(
hosts = 'https://localhost:9200',
username = 'elastic',
password = 'strong_password',
index = 'test_index',
fields = elastic_cols,
verify_certs = False
split_source = True
)
# Write DataFrame to Elastic Index
df.to_elastic(
hosts = 'https://localhost:9200',
username = 'elastic',
password = 'strong_password',
index = 'test_index',
mode = 'w'
)
```
### Redis
```python
import pandas as pd
import pandas_nosql
# Read a DataFrame that was sent to Redis using the to_redis method
# A DataFrame not sent to Redis using the to_redis method is not guaranteed to be read properly
# To Access localhost:
# * host='localhost'
# To persist the DataFrame in Redis use expire_seconds=None
# To set an expiration for the DataFrame pass an integer to expire_seconds
df = pd.read_redis(
host = 'localhost',
port = 6379,
redis_key = 'test_key'
)
# Write a DataFrame to Redis
df.to_redis(
host = 'localhost',
port = 6379,
redis_key = 'test_key',
expire_seconds = None
)
```
### Apache Cassandra
```python
import pandas as pd
import pandas_nosql
# Read an Apache Cassandra table into a Panda DataFrame
# To Access localhost:
# * contact_points=['localhost']
# * contact_points must be a list
df = pd.read_cassandra(
contact_points = ['localhost'],
port = 9042,
keyspace = 'test_keyspace',
table = 'test_table'
)
# Append a DataFrame to Apache Cassandra
# DataFrame Columns must match table Columns
replication = {
'class' : 'SimpleStrategy',
'replication_factor' : 1
}
df.to_cassandra(
contact_points = ['localhost'],
port = 9042,
keyspace = 'test_keyspace',
table = 'test_table',
mode = 'w',
replication = replication
)
```
没有合适的资源?快使用搜索试试~ 我知道了~
pandas-nosql-1.2.0.tar.gz
需积分: 1 0 下载量 41 浏览量
2024-03-07
12:44:57
上传
评论
收藏 9KB GZ 举报
温馨提示
Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
资源推荐
资源详情
资源评论
收起资源包目录
pandas-nosql-1.2.0.tar.gz (11个子文件)
pandas-nosql-1.2.0
pandas_nosql
__init__.py 12KB
setup.py 1KB
LICENSE 11KB
PKG-INFO 4KB
pandas_nosql.egg-info
SOURCES.txt 230B
top_level.txt 13B
PKG-INFO 4KB
requires.txt 14B
dependency_links.txt 1B
setup.cfg 38B
README.md 3KB
共 11 条
- 1
资源评论
程序员Chino的日记
- 粉丝: 3667
- 资源: 5万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功