Mongodb 如何解决类型错误:空';数据帧';:没有要打印的数字数据?

Mongodb 如何解决类型错误:空';数据帧';:没有要打印的数字数据?,mongodb,pandas,pymongo,Mongodb,Pandas,Pymongo,在MongoDB中,我有一个名为twitter的数据库。从数据库中,我试图提取5种更多用于推特的语言。我想用图表显示结果。为此,我使用了pandas和matplotlib。但是在执行代码时,它会说,TypeError:Empty'DataFrame':没有要打印的数字数据 这是我的密码: import pymongo import pandas as pd import matplotlib.pyplot as plt #conect with MongoClient daemon mongod

在MongoDB中,我有一个名为twitter的数据库。从数据库中,我试图提取5种更多用于推特的语言。我想用图表显示结果。为此,我使用了
pandas
matplotlib
。但是在执行代码时,它会说,
TypeError:Empty'DataFrame':没有要打印的数字数据

这是我的密码:

import pymongo
import pandas as pd
import matplotlib.pyplot as plt
#conect with MongoClient daemon mongod
client_con = pymongo.MongoClient()
#conect with db
mydb = client_con["twitter"]
#conect with collection
mycol = mydb["twitterCol"]
#print the records
print mycol.count()

#intiate pandas
tweets = pd.DataFrame()

tweets_data = []
tweets_data= mydb.mycol.find()

"""Next, 3 columns will be added to the tweets 
DataFrame called text, lang, and country. 
Text column contains the tweet, 
Lang column contains the language in which the 
tweet was written, 
and Country the country from which the tweet was sent.
"""

tweets['text'] = map(lambda tweet: tweet["text"], tweets_data)
tweets['lang'] = map(lambda tweet: tweet['lang'], tweets_data)
tweets['country'] = map(lambda tweet: tweet['place']['country'] if tweet['place'] != None else None, tweets_data)


tweets_by_lang = tweets['lang'].value_counts()
tweets_by_lang = tweets_by_lang.astype(int)
fig, ax = plt.subplots()
ax.tick_params(axis='x', labelsize=15)
ax.tick_params(axis='y', labelsize=10)
ax.set_xlabel('Languages', fontsize=15)
ax.set_ylabel('Number of tweets' , fontsize=15)
ax.set_title('Top 5 languages', fontsize=15, fontweight='bold')
tweets_by_lang.plot(ax=ax, kind='bar', color='red')

如何解决这个问题?

你能给我们看一下
tweets\u by_lang.head()
或其内容的样本吗?数据框实际上是空的吗?你能给我们看
tweets\u by_lang.head()
或其内容的样本吗?数据框实际上是空的吗?