Reputation: 39
Hi I have such a dataframe and I want to make it a dictionary like below, I tried to_dict and to_json functions but I didn't get what I wanted. What should I do?
{'http': '188.227.195.68:8080',
'http': '41.207.251.194:8080',
'http': '202.93.229.98:8080',
'http': '46.254.247.59:3130',
...}
Sample Data
http_val proxy
0 http 188.227.195.68:8080
1 http 41.207.251.194:8080
2 http 202.93.229.98:8080
3 http 46.254.247.59:3130
4 http 103.87.236.141:8080
Thank you for your time :)
Upvotes: 0
Views: 148
Reputation: 240
One of the methods to convert arrays to dict
import dask.dataframe as dd
import pandas as pd
import csv
keys = ["key1", "key2", "key3"]
values = ["value1", "value2", "value3"]
list_of_tuples = list(zip(keys, values))
df = pd.DataFrame(list_of_tuples, columns=['Key', 'Value'])
print(df.to_json(orient='records',lines='true'))
Upvotes: 1