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 :: how to iterate through a list in python 
Python :: python iterate list 
Python :: try python import 
Python :: python one line if statement no else 
Python :: random.choice 
Python :: git help 
Python :: while loop python 
Python :: ImportError: /usr/local/lib/python3.7/dist-packages/cv2/cv2.cpython-37m-arm-linux-gnueabihf.so: undefined symbol: __atomic_fetch_add_8 
Python :: decode multipart/form-data python 
Python :: how to have requirement file in python for libs 
Python :: docker django 
Python :: how to write and read dictionary to a file in python 
Python :: pathlib remove extension 
Python :: sort an array python 
Python :: what is the difference between python 2 and 3 
Python :: python pandas convert series to percent 
Python :: pandas dataframe column based on another column 
Python :: how call module in the same directory 
Python :: python json check if key exists 
Python :: how to make a list a string 
Python :: how to capitalize first letter in python 
Python :: mid point formula 
Python :: backtracking python 
Python :: delete a column in pandas 
Python :: join dataframe pandas by column 
Python :: how to find the closest value in column python 
Python :: python working directory 
Python :: audio streaming python 
Python :: filter django or 
Python :: pyqt button clicked connect 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =