how to cast certain key values to floats using python [closed] - python

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Given this dictionary:
my_dict={'animal':['Dog','Cat'],'age':[4,5],'bark':[True,False],'badge_num':['234','896']}
what code will cast 'age' to float?

you could use map combined with float like the following:
my_dict['age']=list(map(float, my_dict['age']))

Related

How can I use several different types inputs together? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 days ago.
Improve this question
multi inputs in python
write a program to take X and Y as input and out put the string x ,repeated y times.
sample input
hi
3
sample output
hi hi hi

I want to print the 3rd highest value along with the 'Id' as the pic [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 months ago.
Improve this question
From here I want to print the 3rd highest value along with the 'Id'. A help would be appreciated
Most_Calori_Burner.nlargest(3)
TRy this,
df.groupby('Id')['Calories'].sum().sort_values(ascending=False).reset_index().iloc[2]
Sort your dataframe in descending order
Reset index and take 3rd value.

How to calculate this mathematical expression in python? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I wanted to calculate this mathematical expression in python3:
Xi = (70 + 1344736401384689745317259585614247891453883777111/315)% 115792089210356248762697446949407573529996955224135760342422259061068512044369
But I'm getting this wrong result: 4.2690044488402846e+45 . Is there something wrong in the expression? how can I fix it to give me the right result?
I think you might be confused because it is showing scientific notation? '{}'.format() should help in that case.
Xi = (70 + 1344736401384689745317259585614247891453883777111/315)% 115792089210356248762697446949407573529996955224135760342422259061068512044369
print('{0:f}'.format(Xi))

How to convert list to integer [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
When I run
print(c)
I get the output
[45]
How do I remove the [ ] and get output like this as an integer?
45
Because I want to print this but It won't run.
print(b[c:c+50])
Take the first element of that array.
print(c[0])

How many items are values in dictionaries, Python [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm looking to find out how to write the code to see how many values a key has in a dictionary.
For example, I'm doing a small survey on a class to see the colour of eyes, I make a dictionary and put all of their names into the dictionary as strings as values. How do i find out how many people have each colour eyes?
survey = {'blue' : ['Kyle', 'Josh', 'Michael']}
len(survey['blue'])

Categories

Resources