{"id":131,"date":"2021-02-26T14:39:49","date_gmt":"2021-02-26T14:39:49","guid":{"rendered":"https:\/\/streetmindfood.com\/plutohash\/?p=131"},"modified":"2021-04-25T20:09:56","modified_gmt":"2021-04-25T20:09:56","slug":"daily-average-fee-by-year-in-usd","status":"publish","type":"post","link":"http:\/\/www.plutohash.com\/2021\/02\/26\/daily-average-fee-by-year-in-usd\/","title":{"rendered":"Daily average Fee by year in USD"},"content":{"rendered":"\n
In this post we’ll see how it’s possible, with just a few lines in Python, to analyze how the average daily cost of fees changes over time, from one year to the next but also from one month to the next. As a reminder, we are analyzing the bitcoin blockchain.<\/p>\n\n\n\n
Let’s start by importing the libraries.<\/p>\n\n\n\n
import blocksci\nimport pandas as pd\nimport seaborn\nimport matplotlib.pyplot as plt\nimport matplotlib.ticker\nimport collections\nimport numpy as np\n%matplotlib notebook<\/code><\/pre>\n\n\n\nInstantiate the chain object:<\/p>\n\n\n\n
chain = blocksci.Blockchain(\"\/BlockSci\/config_file\")<\/code><\/pre>\n\n\n\nWe also use converter <\/code>to express the value of fees in USD. Exchange rates are provided by CoinDesk.<\/p>\n\n\n\nconverter = blocksci.CurrencyConverter()<\/code><\/pre>\n\n\n\nWe use the fees_by_year()<\/code> function to define the year of interest and then be able to apply it to different years. This is the code:<\/p>\n\n\n\ndef fees_by_year(year):\n \n blocks = chain.range(year)\n fees = blocks.fee \/ blocks.tx_count\n times = blocks.time\n \n df = pd.DataFrame({\"Fee\":fees}, index = times)\n df = converter.satoshi_to_currency_df(df, chain)\n ax = df.resample(\"d\").mean().plot(legend=False)\n \n return df, ax <\/code><\/pre>\n\n\n\nNow, we can apply the function by defining the year of our interest. Let’s try the years 2017, 2019, and 2020.<\/p>\n\n\n\n
df_2017,ax_2017 = fees_by_year(\"2017\") <\/code><\/pre>\n\n\n\n