• Register
1 vote
1.1k views

Problem:

I have a data frame to count my daily costs and when I try to input this to my cost using python script it always shows the error:

TypeError: Object of type 'int64' is not JSON serializable

The script I wrote is:

update_list = []
for i in range(len(cost)):
    update_data = {
        'name': cost['entity_name'].iloc[i],
        'count__c': cost['count'].iloc[i] 
    }
    update_list.append(update_data)

all_data_cursor = all_datapull.costforce_login()
all_data_cursor.bulk.Account.update(update_list)

Can anyone help me out to fix this thing. 

 

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

1 vote

Answer:

Jason did not recognise the numpy data types. So you can use encoder to solve this problem:

import json
import numpy as np

class Npencoder(json.JSONencoder):
    def default(self, obj):
        if isinstance(obj, np.integer):
            return int(obj)
        elif isinstance(obj, np.floating):
            return float(obj)
        elif isinstance(obj, np.ndarray):
            return obj.tolist()
        else:
            return super(Npencoder, self).default(obj)
(

 Write your codes here
)
json.dumps(data, cls=Npencoder)

I hope you understand what I said. Hope this helps you.

Happy coding.

11 6 4
34,950 points

Related questions

0 votes
1 answer 18 views
18 views
Problem: "TypeError: (Integer) is not JSON serializable" when serializing JSON in Python?
asked Apr 17 Supti 13k points
0 votes
1 answer 3 views
3 views
Question: I have a basic dict as follows: sample = {} sample['title'] = "String" sample['somedate'] = somedatetimehere When I try to do jsonify(sample) I get: TypeError: datetime.datetime(2012, 8, 8, 21, 46, 24, 862000) is not JSON serializable What can I do ... from the retrieval of records out of mongodb where when I print out str(sample['somedate']), the output is 2012-08-08 21:46:24.862000.
asked Apr 20 munim01 21k points
0 votes
1 answer 21 views
21 views
Problem: "TypeError: (Integer) is not JSON serializable" when serializing JSON in Python?
asked Apr 17 Moumita Bhowmick 12.9k points
0 votes
1 answer 2 views
2 views
Problem: Is there someone who knows how to resolve this issue? >Typeerror: object of type 'int64' is not json serializable.
asked 5 days ago Florina Gulnar 7.9k points
0 votes
1 answer 23 views
23 views
Problem: How to I Solve this: python typeerror: 'nonetype' object is not iterable HELP! I need help understanding this: python typeerror: 'nonetype' object is not iterable Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 3 Mashhoodch 13k points
0 votes
1 answer 25 views
25 views
Problem: I am looking to make a loop so that for each element in the list, it will get broken down into each of it's characters. For example, say the number 137 was in the list then it would be turned into [1,3,7]. Then I want to add these numbers together (I ... it). However, I keep getting the error message TypeError: 'int' object is not iterable when I try and run this. What am I doing wrong?
asked Feb 23 Mashhoodch 13k points
0 votes
1 answer 26 views
26 views
Problem: I’m working on the count problem, and have come up with the following code: def count(sequence, item): found = 0 for i in len(sequence): if sequence[i] == item: found = found + 1 return found
asked Jan 22 Mashhoodch 13k points
0 votes
1 answer 57 views
57 views
On making a small program for math there returned an error "TypeError: 'NoneType' object is not subscriptable. Never before has been seen, this error, so no idea what it means. import math print("The format you should consider:") print str("value 1a")+str(" + ")+ ... /Nathan/Documents/Python/New thing", line 16, in <module> a = lista[1] - lista[0] TypeError: 'NoneType' object is not subscriptable
asked Oct 24, 2020 psandprop 2.4k points
0 votes
1 answer 56 views
56 views
Problem: how to I Solve this: typeerror: a bytes-like object is required, not 'int' HELP! I need help understanding this: typeerror: a bytes-like object is required, not 'int' Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 8 Mashhoodch 13k points
0 votes
1 answer 89 views
89 views
Problem: What the traceback error is pointing out is the misuse of for statement: for i in Updt():. for in python 3 i "Python's for statement iterates? How function' object is not iterable. from getWords import getWords unique = [] def findUniqueWords(words): for word in words
asked Feb 15 Mashhoodch 13k points