Python入門數(shù)據(jù)導(dǎo)入導(dǎo)出

學(xué)習(xí)python數(shù)據(jù)分析最重要最核心的兩個包就是numpy和pandas,掌握了這兩個數(shù)據(jù)中的方法是Python入門必備,下面時數(shù)據(jù)導(dǎo)入和導(dǎo)出的方法。

數(shù)據(jù)包的導(dǎo)入(python 3.X)

import numpy as np???? #導(dǎo)入numpy數(shù)據(jù)包并簡寫為np

import pandas as pd?? #導(dǎo)入pandas數(shù)據(jù)包并簡寫為pd

數(shù)據(jù)的導(dǎo)入

pd.read_csv(filename) ?? # 導(dǎo)入csv格式文件中的數(shù)據(jù)

pd.read_table(filename) ?? # 導(dǎo)入有分隔符的文本 (如TSV) 中的數(shù)據(jù)

pd.read_excel(filename)??? # 導(dǎo)入Excel格式文件中的數(shù)據(jù)

pd.read_sql(query,connection_object)??? # 導(dǎo)入SQL數(shù)據(jù)表/數(shù)據(jù)庫中的數(shù)據(jù)

pd.read_json(json_string)?? # 導(dǎo)入JSON格式的字符,URL地址或者文件中的數(shù)據(jù)

pd.read_html(url)?? # 導(dǎo)入經(jīng)過解析的URL地址中包含的數(shù)據(jù)框 (DataFrame) 數(shù)據(jù)

pd.read_clipboard()?? # 導(dǎo)入系統(tǒng)粘貼板里面的數(shù)據(jù)

pd.DataFrame(dict)?? # 導(dǎo)入Python字典 (dict) 里面的數(shù)據(jù),其中key是數(shù)據(jù)框的表頭,value是數(shù)據(jù)框的內(nèi)容。

數(shù)據(jù)的導(dǎo)出

df.to_csv(filename)?? # 將數(shù)據(jù)框 (DataFrame)中的數(shù)據(jù)導(dǎo)入csv格式的文件中

df.to_excel(filename)?? # 將數(shù)據(jù)框 (DataFrame)中的數(shù)據(jù)導(dǎo)入Excel格式的文件中

df.to_sql(table_name,connection_object)?? # 將數(shù)據(jù)框 (DataFrame)中的數(shù)據(jù)導(dǎo)入SQL數(shù)據(jù)表/數(shù)據(jù)庫中

df.to_json(filename)?? # 將數(shù)據(jù)框 (DataFrame)中的數(shù)據(jù)導(dǎo)入JSON格式的文件中

實例

使用anaconda下的jupyter notebook

pytnon代碼

將生成的數(shù)字保存為csv格式的文件

pytnon代碼

在home中找到dataset名的文件再打開

文件中數(shù)據(jù)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容