學(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

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

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