數(shù)據(jù)處理是對(duì)收集到的數(shù)據(jù)進(jìn)行加工整理蠢沿,以達(dá)到適合數(shù)據(jù)分析的樣式惑灵,是數(shù)據(jù)分析必不可少的階段
數(shù)據(jù)導(dǎo)入
1. 數(shù)據(jù)的存在形式
![Paste_Image.png](http://upload-images.jianshu.io/upload_images/4577447-49bc183181bc159d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Paste_Image.png
2. 三種文件導(dǎo)入方式
![Paste_Image.png](http://upload-images.jianshu.io/upload_images/4577447-a7bba5cb9e0de8a3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Paste_Image.png
- 導(dǎo)入CSV文件(使用 read_csv() 函數(shù))
from pandas import read_csv
df = read_csv(
'D://PDA//4.1//info.csv'
)
df
- 導(dǎo)入文本文件(使用 read_table() 函數(shù))
from pandas import read_table
df = read_table(
'D://PDA//4.1//info.txt',
name=['age','name'],
sep=','
)
df
- 導(dǎo)入Excel文件(使用 read_excel() 函數(shù))
from pandas import read_excel
df = read_excel(
'D://PDA//4.1//info.xlsx',
sheetname='data'
)
df
數(shù)據(jù)導(dǎo)出
Python數(shù)據(jù)導(dǎo)出使用to_csv函數(shù)
代碼
設(shè)置index=false溺森,可以去掉導(dǎo)出數(shù)據(jù)的默認(rèn)索引
from pandas import DataFrame
df.to_CSV(
"D:\\PDA\\4.2\\df.csv",
index=false
)