0

I'm trying to visualize the correlation between POS values. From the list below I want to generate a dataframe where columns are equal to keys and the first row is equal to values.

I need this, to, after, plot df.corr()

Here are the variables:

keys = Counter(list_tag).keys()
keys
dict_keys(['NNP', 'VBZ', 'DT', 'NN', '.', 'PRP', 'VBD', 'IN', 'JJ', 'NNS', ',', '``', 'NNPS', "''", 'PRP$', 'CD', 'VB', 'TO', 'POS', 'RB', 'RBR', 'WP', 'MD', 'VBP', 'CC', 'WRB', 'WDT', 'RP', ':', 'VBN', 'VBG', 'EX', '(', 'JJR', ')', 'PDT', 'FW', 'RBS', 'JJS', 'UH'])
values = Counter(list_tag).values()
values
dict_values dict_values([282, 110, 259, 426, 106, 132, 60, 275, 204, 98, 119, 12, 3, 11, 41, 24, 80, 46, 25, 177, 7, 14, 30, 64, 112, 13, 10, 10, 21, 45, 42, 11, 12, 8, 12, 1, 1, 1, 2, 4])

My trouble is this: calling df = pd.DataFrame(Counter(list_tag), index=Counter(list_tag).keys()) As shown below, I'm writing something wrong because I need only the first row.

image

Is there an efficient solution to accomplish this without manual dropping of df.iloc[2:] Thank you!

1
  • 1
    I think you are missing a .values. It should be like pd.DataFrame(Counter(list_tag).values(), index=Counter(list_tag).keys()). Also you could save Counter(list_tag) to a variable Commented Oct 26, 2021 at 16:35

1 Answer 1

1
keys = ['NNP', 'VBZ', 'DT', 'NN', '.', 'PRP', 'VBD', 'IN', 'JJ', 'NNS', ',', '``', 'NNPS', "''", 'PRP$', 'CD', 'VB', 'TO', 'POS', 'RB', 'RBR', 'WP', 'MD', 'VBP', 'CC', 'WRB', 'WDT', 'RP', ':', 'VBN', 'VBG', 'EX', '(', 'JJR', ')', 'PDT', 'FW', 'RBS', 'JJS', 'UH']
values = [282, 110, 259, 426, 106, 132, 60, 275, 204, 98, 119, 12, 3, 11, 41, 24, 80, 46, 25, 177, 7, 14, 30, 64, 112, 13, 10, 10, 21, 45, 42, 11, 12, 8, 12, 1, 1, 1, 2, 4]

df = pd.DataFrame(values, index=keys).transpose()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.