匯出 python 資料

2021-08-14 04:20:54 字數 1262 閱讀 6379

可以用__dict__將類的資料變成乙個 dictionary ,然後使用

import json

str= json.dumps(mydict)

# 將類的資料匯出成 json 格式的 string 然後用檔案讀寫或者重定向的方式匯出

json.dump(

**args)

# 直接匯出至檔案

官方文件鏈結

簡單的使用方法:(這一段摘自 sklearn )

>>

>

from sklearn import svm

>>

>

from sklearn import datasets

>>

> clf = svm.svc(

)>>

> iris = datasets.load_iris(

)>>

> x, y = iris.data, iris.target

>>

> clf.fit(x, y)

svc(c=

1.0, cache_size=

200, class_weight=

none

, coef0=

0.0,

decision_function_shape=

'ovr'

, degree=

3, gamma=

'auto'

, kernel=

'rbf'

, max_iter=-1

, probability=

false

, random_state=

none

, shrinking=

true

, tol=

0.001

, verbose=

false

)>>

>

import pickle

>>

> s = pickle.dumps(clf)

>>

> clf2 = pickle.loads(s)

>>

> clf2.predict(x[0:

1])array([0

])>>

> y[0]

0

與 json 的比較,參考 python3的文件12.1.1.2. comparison with json

python實現資料匯入匯出mysql

匯入需要的python包 import pymysql import traceback import pandas as pd from sqlalchemy import create engine import os import numpy as np將sql查詢結果匯出檔案 def mys...

資料匯出Excel表 資料庫資料匯出

public static hashmapcolumn new hashmap static param table 要匯出的表 param name 匯出的excel表名稱 表頭 throws exception public void createexcel string table,strin...

MySQL匯出匯出資料庫

預設匯出路徑為mysql的內建路徑,因此這裡都加上了 documents 作為路徑。匯出整個資料庫 mysqldump u root p test documents test.sql 匯出資料庫乙個表 mysqldump h hostname u username p password datab...