-1

I need to copy values only from a DF to a dict for the purposes of a display function that takes a dict as an argument.

My dataframe is called databases in the following excerpt.

DB_stat_reporting = dict()
report_month = databases.loc[databases['Date'] == reporting_month]
last_year    = databases.loc[databases['Date'] == past_year]

report_month

Output:

    Date        Circ    EB  Mag     bla     drive   Total   Digi
12  2019-12-01  118324  133 1084    4928    17513   141982  23658

I need to pass the values only to a dictionary:

DB_stat_reporting['Circ']     = report_month['Circ']
DB_stat_reporting['Circ']

Produces:

12    118324

I need to run some stats on it so it needs to stay an int but I do not want the index or brackets, etc. to be printed.

Expected output:

118324

This seemed like such a simple thing but I can not get it to do this.

Bubnoff
  • 3,917
  • 3
  • 30
  • 33
  • Have you done any research? This seems like basic Pandas functionality. – AMC Jan 22 '20 at 00:31
  • 1
    Does this answer your question? [How to get a value from a cell of a dataframe?](https://stackoverflow.com/questions/16729574/how-to-get-a-value-from-a-cell-of-a-dataframe) – AMC Jan 22 '20 at 00:31
  • @AMC I basically overthought this. Project rush and brain freeze. Should I delete this? – Bubnoff Jan 22 '20 at 22:17
  • 1
    You might find this useful: https://stackoverflow.com/help/what-to-do-instead-of-deleting-question. – AMC Jan 22 '20 at 22:22

1 Answers1

0

Use DataFrame.loc to get the value itself without the index:

DB_stat_reporting = dict()
DB_stat_reporting['Circ'] = report_month.loc[12, 'Circ']

Or Series.iat:

DB_stat_reporting = dict()
DB_stat_reporting['Circ'] = report_month['Circ'].iat[0]
print(DB_stat_reporting)

{'Circ': 118324}
Erfan
  • 40,971
  • 8
  • 66
  • 78