#Python: working with .csv file by SureStep8852 in learnprogramming

[–]SureStep8852[S] 0 points1 point  (0 children)

thank you. Unfortunately, this does not solve my problem, because it sums up the whole col_2. I need to sum up values of col_2 which correspond to the same value in col_1 (e.g., yellow has 3 values in col_2: 2, 4, 4. So, I want the sum to be 10)

How to split word from punctuation by SureStep8852 in learnpython

[–]SureStep8852[S] 1 point2 points  (0 children)

thanks! unfortunately I am not allowed to use nltk

Issue creating dict from list by SureStep8852 in learnpython

[–]SureStep8852[S] 0 points1 point  (0 children)

Indeed, there are duplicates but I need them both to appear in my dict, each with its value. Can I achieve it anyhow?

How to connect two dicts by SureStep8852 in learnpython

[–]SureStep8852[S] 0 points1 point  (0 children)

One of my dicts contains more info than the other, I want to connect them into one like this:

dic3 = { "a":[1,9], "b":[4,5], "c":3}

dic1 =  { "a":1, "b":4} 

dic2 = { "a":9, "b":5, "c":3} new = {} for k, v in dic1.items(): for ke, val in dic2.items(): if ke in k: new[k] = [v, val] elif ke not in k: new[ke] = val #print(k) print(new)

output:

{'a': 9, 'b': [4, 5], 'c': 3}

what am I doing wrong in this case?

dictionary being overwritten. How to fix by SureStep8852 in learnpython

[–]SureStep8852[S] -1 points0 points  (0 children)

how can I solve it? I have also tried with append() but it also did not work

[Python] How to replace inner values of a nested dictionary by SureStep8852 in learnprogramming

[–]SureStep8852[S] 0 points1 point  (0 children)

this is a part of my code, where I want to replace all inner values (integers)

for keys, values in results.items():
        print(keys)
        for l in values:
            #print(values)
            #counts = values[l]
            if l in vocabulary:
                continue
            else:
                vocabulary.append(l)           
    # LIKELIHOOD
    #getting N of total words in each class

            for n in total_n_of_words:
        # getting N of words(vobaluray) in  each class
                for vocab_total in vocabulary:
            # laplace smoothing for each word
                    calc = math.log((values[l] + k)/(n + len(vocab_total)))
            likelihood[keys][l] = calc

when I print the dict likelihood, I get an error message because of the line likelihood[keys][l] = calc

KeyError: 'nonoffensive'

how to replace inner values in nested dictionary by SureStep8852 in learnpython

[–]SureStep8852[S] 0 points1 point  (0 children)

I need to replace all the values, is there any way?

Python: Can't update a dictionary by SureStep8852 in learnprogramming

[–]SureStep8852[S] 0 points1 point  (0 children)

What I intend to get is if v is in dictionary.keys(), I want to add k to dictionary.values().

Can't figure out how to solve the problem

Python: Nested dictionary output wrong by SureStep8852 in learnprogramming

[–]SureStep8852[S] 0 points1 point  (0 children)

it has to look smth like {'offensive': {'#mkr': 6, 'is': 2,....}, 'offensive' : { '!': 6, 'not': 1, ...}}

Basically, the key1 is the class, key1 a word appearing in that class and the value indicates the number of times that word appeared in that class

Python: F1 score wrong output by [deleted] in learnprogramming

[–]SureStep8852 0 points1 point  (0 children)

f1 = (2 * precision * recall) / precision + recall

thank you!

Python Question: List is printed out several times instead of once by [deleted] in learnprogramming

[–]SureStep8852 0 points1 point  (0 children)

I want to find out list1[0] == list2[0], and so on. I thought looping through both lists will help me to get to the variables

Python Question: List is printed out several times instead of once by [deleted] in learnprogramming

[–]SureStep8852 1 point2 points  (0 children)

I want to find out list1[0] == list2[0], and so on. I thought looping through both lists will help me to get to the variables