时间:2021-07-01 10:21:17 帮助过:50人阅读
#导入相应的包 import pymongo import pandas as pd from pandas import Series,DataFrame #连接数据库 client = pymongo.MongoClient(‘localhost‘,27017) db = client[‘python‘]
# 授权 db.authenticate(name=‘lu‘,password=‘123456‘,source=‘admin‘) info = db[‘NBA‘] #加载数据 data = DataFrame(list(info.find())) print(data) # 写入CSV文件 data.to_csv(‘NBA.csv‘) import csv import pandas as pd from matplotlib import pyplot as plt filename = ‘NBA.csv‘ with open(filename,encoding=‘UTF-8‘) as f: data = pd.read_csv(f) # team = data[‘team队伍‘] p3 = data[‘p3三分球命中次数‘] p3a = data[‘p3a三分球投射次数‘] p2 = data[‘p2二分球命中次数‘] p2a = data[‘p2a三分球投射次数‘]
python-pandas读取mongodb、读取csv文件
标签:需要 连接数据库 爬取 nbsp 取出 csv 关于 ODB encoding