嗨,我有一个这样的数据框,我想使其像下面的字典,我尝试了to_dict和to_json函数,但是我没有得到想要的东西。我该怎么办?
{'http': '188.227.195.68:8080',
'http': '41.207.251.194:8080',
'http': '202.93.229.98:8080',
'http': '46.254.247.59:3130',
...}
样本数据
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
谢谢您的时间:)
答案 0 :(得分:1)
将数组转换为字典的方法之一
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'))