Chuck norris jokes challenge

Sir I have extracted the data but not able to write it to csv files.Pl tell how to do this

Hey @ayush15goel, take reference from this code,

#!/usr/bin/env python
# coding: utf-8

# In[7]:


import json
import requests
import pandas as pd
import os 

url="http://api.icndb.com/jokes/json?"# url


pr={
"value":""
}

r=requests.get(url,params=pr)

d=r.content

p=json.loads(d)

m=p["value"]

t=pd.read_csv("./Test/ID.csv").values # this is my device location where the testcases are saved, here you give your path where your testcases are downloaded

t=t.reshape(-1,)

a_jokes=[]
for i in range(len(m)):
#if id is matched with the id given in testcases
    if(m[i]['id'] in t):
        joke=m[i]['joke']
        a_jokes.append(joke)

df=pd.DataFrame({'ID':t, 'joke': a_jokes})
# this make a CSV file name abhishek.csv and saved the all data into it
df.to_csv("aashi.csv",index=False)

Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section. :blush:

sir can you pl explain-t=t.reshape(-1,) statement

and what does “index=False” do in last line

Hey @ayush15goel, we have used in t= t.reshape(-1,) just to convert in vector, initially it was in (473,1) and we have used in the" if(m[i][‘id’] in t):" which required a linear array.

We have done index = False, bcz to_csv function automatically adds one column when in makes csv file, with values 0,1,2,3… But we do not need them…

Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section . :blush:

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.