[英]Reading CSV file as a key value pair
I have a CSV file as mentioned below.我有一个 CSV 文件,如下所述。 CSV file content:
CSV文件内容:
NAME![]() |
SURNAME![]() |
AGE![]() |
---|---|---|
Shri![]() |
siri![]() |
23 ![]() |
Golu![]() |
Kumar![]() |
25 ![]() |
I need to read this CSV file as a key value pair.我需要将此 CSV 文件作为键值对读取。
[{'NAME':'Shri', 'Surname':'siri', 'Age':'23'}] [{'NAME':'Shri', '姓氏':'siri', '年龄':'23'}]
[{'NAME':'Golu', 'Surname':'Kumar', 'Age':'25'}] [{'NAME':'Golu', '姓氏':'Kumar', '年龄':'25'}]
Use records
argument使用
records
参数
df.to_dict('records')
Or to get output as the one you provided或者获取 output 作为您提供的那个
df1 = df.to_dict('records')
_list =[]
for i in range(len(df1)):
_list.append(df1[i])
_list
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.