text: #!/usr/bin/env python
  # coding: utf-8
  
  # In[2]:
  
  
  import os
  
  import numpy as np
  import pandas as pd
  
  os.makedirs("./output_tables/foodmine_dataset_statistics/", exist_ok=True)
  os.makedirs("./figures/foodmine_dataset_statistics/", exist_ok=True)
  
  # In[3]:
  
  
  data = pd.read_csv("./data/full_data.csv")
  data = data[data.food.isin(["garlic", "cocoa"])]
  
  
  # In[33]:
  
  
  num_papers_by_food = data.groupby("food").agg({"PMID": lambda x: len(np.unique(x))})
  num_papers_by_food.to_csv(
      "./output_tables/foodmine_dataset_statistics/num_papers_by_food.csv"
  )
  
  
  # In[25]:
  
  
  datapoints_by_journal = (
      data.groupby("Journal/Book").agg({"PMID": len}).sort_values("PMID", ascending=False)
  )
  dois_by_journal = (
      data.groupby("Journal/Book")
      .agg({"PMID": lambda x: len(np.unique(x))})
      .sort_values("PMID", ascending=False)
  )
  
  
  # In[26]:
  
  
  datapoints_by_journal.to_csv(
      "./output_tables/foodmine_dataset_statistics/datapoints_by_journal.csv"
  )
  dois_by_journal.to_csv(
      "./output_tables/foodmine_dataset_statistics/dois_by_journal.csv"
  )
  
  
  # In[27]:
  
  
  datapoints_by_publisher = (
      data.groupby("publisher").agg({"PMID": len}).sort_values("PMID", ascending=False)
  )
  dois_by_publisher = (
      data.groupby("publisher")
      .agg({"PMID": lambda x: len(np.unique(x))})
      .sort_values("PMID", ascending=False)
  )
  
  
  # In[30]:
  
  
  datapoints_by_publisher.to_csv(
      "./output_tables/foodmine_dataset_statistics/datapoints_by_publisher.csv"
  )
  dois_by_publisher.to_csv(
      "./output_tables/foodmine_dataset_statistics/dois_by_publisher.csv"
  )
  
  
  # In[36]:
  
  
  import matplotlib.pyplot as plt
  
  # In[43]:
  
  
  csum = dois_by_publisher["PMID"].cumsum() / dois_by_publisher["PMID"].sum()
  csum.plot(figsize=(20, 5))
  plt.xticks(
      list(csum.reset_index().index), labels=csum.index, rotation=90
  )  # Rotates X-Axis Ticks by 45-degrees
  plt.gca().axhline(0.8, linestyle="--", c="black")
  plt.gca().axhline(0.9, linestyle="--", c="black")
  plt.title("Cumulative number of papers by publisher")
  plt.savefig("./figures/foodmine_dataset_statistics/cumul_papers_by_publisher.svg")
  
  
  # In[44]:
  
  
  csum = datapoints_by_publisher["PMID"].cumsum() / datapoints_by_publisher["PMID"].sum()
  csum.plot(figsize=(20, 5))
  plt.xticks(
      list(csum.reset_index().index), labels=csum.index, rotation=90
  )  # Rotates X-Axis Ticks by 45-degrees
  plt.gca().axhline(0.8, linestyle="--", c="black")
  plt.gca().axhline(0.9, linestyle="--", c="black")
  plt.title("Cumulative number of data points by publisher")
  plt.savefig("./figures/foodmine_dataset_statistics/cumul_datapoints_by_publisher.svg")
  