NULL COUNT IN UNCLEANED PLACE
Tue Jun 18 2024 20:35:44 GMT+0000 (Coordinated Universal Time)
Saved by
@madgakantara
from pymongo import MongoClient
import matplotlib.pyplot as plt
# MongoDB connection details
mongo_uri = "mongodb://localhost:27017/"
database_name = "twitter_database"
collection_name = "tweets"
# Connect to MongoDB
client = MongoClient(mongo_uri)
db = client[database_name]
collection = db[collection_name]
# Initialize counters
null_count = 0
not_null_count = 0
cursor = collection.find()
for doc in cursor:
if doc.get("json_data", {}).get("place") is None:
null_count += 1
else:
not_null_count += 1
# Data for the bar chart
categories = ['Null', 'Not Null']
counts = [null_count, not_null_count]
# Plotting the bar chart
plt.bar(categories, counts, color=['blue', 'orange'])
plt.xlabel('Place Value')
plt.ylabel('Count')
plt.title('Count of Null vs Not Null values in json_data.place')
plt.show()
content_copyCOPY
Comments