Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas to dict by row

data_dict = pd.read_csv('file.csv').to_dict(orient='records')
Comment

pandas dict from row

import pandas as pd

# your df
# =========================
print(df)

   id  score1  score2  score3  score4  score5
0   1  0.0000  0.1087  0.0000  0.0786       1
1   2  0.0532  0.3083  0.2864  0.4464       1
2   3  0.0000  0.0840  0.8090  0.2331       1

# to_dict
# =========================
df.to_dict(orient='records')

Out[318]: 
[{'id': 1.0,
  'score1': 0.0,
  'score2': 0.10865899999999999,
  'score3': 0.0,
  'score4': 0.078597,
  'score5': 1.0},
 {'id': 2.0,
  'score1': 0.053238000000000001,
  'score2': 0.308253,
  'score3': 0.28635300000000002,
  'score4': 0.44643299999999997,
  'score5': 1.0},
 {'id': 3.0,
  'score1': 0.0,
  'score2': 0.083978999999999998,
  'score3': 0.80898300000000001,
  'score4': 0.23305200000000001,
  'score5': 1.0}]
Comment

PREVIOUS NEXT
Code Example
Python :: python difflib compare two strings 
Python :: python parse url get parameters 
Python :: when was python created 
Python :: radix sort python 
Python :: django login_required decorator 
Python :: how to determine python project parent dir 
Python :: fastapi json request 
Python :: godot setget 
Python :: how to import include in django 
Python :: check if dataframe contains infinity 
Python :: how to sum certain columns row wise in python 
Python :: example of django template for forms 
Python :: pandas index from 1 
Python :: convert float to integer pandas 
Python :: django media root 
Python :: python series get value 
Python :: pandas change dtype to timestamp 
Python :: panda3d 
Python :: exclude index column pandas 
Python :: exec: "python": executable file not found in $PATH Error compiling for board ESP32 Dev Module. 
Python :: python how to change back to the later directory 
Python :: create a dictionary in python 
Python :: python pandas apply function to one column 
Python :: install python 3.7 centos 
Python :: python reserved keywords 
Python :: how to make django model field case insensitive 
Python :: find all files containing a string in python with glob module 
Python :: dataframe move row up one 
Python :: python opencv imresize 
Python :: remove punctuation python string library 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =