My code is giving errored message after submission
My code:
Chuck Norris Jokes
hey @naazsayma123 ,
i didn’t get that errored message after submission ?
Can you be please more clear on it.
Thank You .
hey @naazsayma123 ,
Can you please check the submission file contains correct number of rows as required in the submission file and also it has the same format as of submission file.
If its all ok , then i would request you to kindly share me your submission file, so that i can check it once.
To share , you can upload it on drive and share me the link here.
I hope this helps.
@prashant_ml
link of file
https://docs.google.com/spreadsheets/d/1IpGcXQegJ06I4UXqaf4ASUpA_tdxzLROktBfFbd4U-w/edit#gid=1688579376
hey @naazsayma123,
your csv file is generated in wrong format.
Can you please provide me your code too , i guess you have approached in wrong way.
hey @naazsayma123,
you dont need to dump the json into it.
Kindly check the sample submission once again.
it should be a csv file that contains records as
–> id,joke
–> id,joke
–> id,joke
–> id,joke
–> id,joke
–> id,joke
–> id,joke
Like this.
have a look at this link , this will explain you in much better way.
@prashant_ml
I did the same thing.
when I am executing json_data[‘value’][‘joke’] it throwing an error
do one thing ,
upload your code on drive and share me the link.
@prashant_ml
here is the drive link of my code:
https://drive.google.com/file/d/1qZC-gpSE0joqgvb4gBttS3yg1YNIIXuF/view?usp=sharing
hey @naazsayma123 ,
You need to change some codes and use pandas to save your data.
As csv files depend upon , ( comma ) to separate while reading. Although you are doing it correctly by providing the newline but still its not getting readed at the backend properly.
So , just change the followings
result=eval(json.dumps(res))
and to save the file
import pandas as pd
csv = pd.DataFrame(result)[['id','joke']]
csv.to_csv("submission.csv",index=False)
actually your json.dumps function is creating a list stored in string format.
so to get that list i used eval function.
and then i have used pandas that is a library meant for the purpose of dealing with tables.
So it reads the data in correct format as needed and then i took only the required columns and saved into another array.
index = false is used because on saving pandas adds another column, like serial no. , hence as we do not need them , hence did it as such.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.