<jupyter_start><jupyter_text>Importing the libraries<jupyter_code>from pandasdmx import Request
import pandas as pd
from bokeh.io import output_notebook, show
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, LabelSet
output_notebook()<jupyter_output><empty_output><jupyter_text>Connecting to the webservice<jupyter_code>estat = Request('ESTAT')<jupyter_output><empty_output><jupyter_text>Downloading dataflow definitions<jupyter_code>dflow = estat.dataflow()<jupyter_output><empty_output><jupyter_text>Defining functions  Data structure<jupyter_code>def dsd_resp(id):
    """
    The function takes a dataflow identifier and requests from the Eurostat SDMX api the dataflow's datastructure, datastructure id and datastructure response.
    """    
    # Defining the data set's dataflow based on the data set id.
    df = dflow.dataflow[id]
    
    # Printing the table's name
    print("The table's name:")
    print(dflow.write().dataflow.loc[id][0])
    
    # Acquiring the dataflow's datastructure id
    dsd_id = df.structure.id
    
    # Requesting for the dataflow's datastructure
    dsd_resp = estat.get(resource_type = 'datastructure', resource_id = dsd_id)
    
    # Requesting the dataflow's datastructure
    dsd = dsd_resp.datastructure[dsd_id]
    
    return dsd_resp, dsd_id, dsd<jupyter_output><empty_output><jupyter_text>Datastructure attributes<jupyter_code>def dsd_att(dsd):
    """The function takes a table datastructure definition and prints its measure, dimension and attribute lists."""
    # Measures
    print("Measures:")
    print(dsd.measures.aslist())
    
    # Dimensions
    print("\nDimensions:")
    print(dsd.dimensions.aslist())
    
    # Attributes
    print("\nAttributes:")
    print(dsd.attributes.aslist())<jupyter_output><empty_output><jupyter_text>Selecting the tables  Listing the tables from the 'High-tech industry and knowledge-intensive services (**htec**)' database<jupyter_code>dflow.write().dataflow[dflow.write().dataflow.index.str.startswith('htec') == True]<jupyter_output><empty_output><jupyter_text>The tables I am going to analyze<jupyter_code>id1 = 'htec_sti_exp2'
dflow.write().dataflow.loc[id1][0]
id2 = 'htec_vci_stage2'
dflow.write().dataflow.loc[id2][0]<jupyter_output><empty_output><jupyter_text>Venture capital data  Getting the table's dataflow definition and datastructure<jupyter_code>dsd_resp2, dsd_id2, dsd2 = dsd_resp(id2)<jupyter_output>The table's name:
Venture capital investment by detailed stage of development (from 2007, source: EVCA)<jupyter_text>Downloading the table's datastructure definition<jupyter_code>dsd_att(dsd2)<jupyter_output>Measures:
[PrimaryMeasure | OBS_VALUE]

Dimensions:
[Dimension | FREQ, Dimension | EXPEND, Dimension | UNIT, Dimension | GEO, TimeDimension | TIME_PERIOD]

Attributes:
[DataAttribute | OBS_FLAG, DataAttribute | OBS_STATUS]<jupyter_text>Codelist:<jupyter_code>dsd_resp2.write().codelist.loc[:,:] # [['EXPEND', 'UNIT'],:]<jupyter_output><empty_output><jupyter_text>Requesting the data<jupyter_code>dresp2 = estat.get(resource_type = 'data',
                   resource_id = id2,
                   params = {'references': None,
                             #'startPeriod': '2014',
                             #'endPeriod': '2014'
                            })
dat2 = dresp2.data
dat2.dim_at_obs
ser2 = list(dat2.series)
len(ser2)
ser2[5].key
set(s.key.UNIT for s in dat2.series)<jupyter_output><empty_output><jupyter_text>Writing the data into DataFrame<jupyter_code>iter2 = (s for s in dat2.series if (s.key.GEO in ['EU15']) == False)
tab2 = dresp2.write(iter2)
tab2 = tab2.stack('GEO')
tab2.columns = tab2.columns.droplevel(['FREQ']) # Dropping 'FREQ' and 'UNIT' levels
tab2.swaplevel('UNIT', 'EXPEND', axis = 1)
tab2 = tab2.loc['2015', ['PC_GDP', 'MIO_EUR']]
# tab2.dropna(axis = 0, how = 'any', inplace = True)
tab2.index = tab2.index.droplevel(0) # Dropping the 'TIME_PERIOD' axis
tab2
source = ColumnDataSource(data = dict(names = list(tab2.index), invest = tab2.loc[:,('PC_GDP','INV')], venture = tab2.loc[:,('PC_GDP','INV_VEN')]))

p = figure(plot_width = 600, plot_height = 600)
p.square(x = tab2.loc[:,('PC_GDP','INV')], y = tab2.loc[:,('PC_GDP','INV_VEN')], size = list(tab2.loc[:,('MIO_EUR','INV')] / 500), color = "blue", alpha = 0.6)

p.xaxis.axis_label = 'Total R&D Investment'
p.yaxis.axis_label = 'Venture Capital R&D Investment'

labels = LabelSet(x = 'invest',
                  y = 'venture',
                  text = 'names',
                  source = source,
                  render_mode='canvas',
                  level='glyph')

p.add_layout(labels)
show(p)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12920505678165844, 'fraction_numerical': 0.017141632740518536, 'mean_word_length': 4.583732057416268, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '595342', 'license': 'Apache-2.0', 'n_tokens_mistral': 1700, 'n_tokens_neox': 1636, 'n_words': 324, 'path': 'Eurostat/Venture Capital.ipynb', 'repo_name': 'nocibambi/r-d-inv-dat', 'size': '4667'}