新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:如何用python處理數(shù)據(jù)
Python處理數(shù)據(jù)利器 → Pandas

創(chuàng)新互聯(lián)公司專注于文成企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,商城網(wǎng)站建設(shè)。文成網(wǎng)站建設(shè)公司,為文成等地區(qū)提供建站服務(wù)。全流程按需策劃,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)
數(shù)據(jù)一般格式:csv/xlsx
如何用pandas讀取數(shù)據(jù)
案例:用pandas處理商鋪數(shù)據(jù)
用pandas處理
導(dǎo)入模塊
import pandas as pd
# 導(dǎo)入pandas模塊
import warnings
warnings.filterwarnings('ignore')
# 不發(fā)出警告
print('成功導(dǎo)入模塊')
# 如何用pandas讀取數(shù)據(jù) - csv
df = pd.read_csv('/home/kesci/商鋪數(shù)據(jù).csv')
print(type(df),df['name'].dtype) # 查看df類型,查看df中一列的數(shù)值類型
df.head()
# 用pandas處理商鋪數(shù)據(jù) - comment字段清洗
df1 = df[df['comment'].str.contains('條')]
df1['comment'] = df1['comment'].str.split('條').str[0]
print(df1['comment'].dtype)
df1['comment'] = df1['comment'].astype('int')
print(df1['comment'].dtype) # 更改列數(shù)值類型
df1.head()
# 用pandas處理商鋪數(shù)據(jù) - price字段清洗
df1 = df1[df1['price'].str.contains('¥')]
df1['price'] = df1['price'].str.split('¥').str[-1]
df1['price'] = df1['price'].astype('float')
print(df1['price'].dtype) # 更改列數(shù)值類型
df1.head()更多學(xué)習(xí)內(nèi)容,請點(diǎn)擊Python學(xué)習(xí)網(wǎng)!
文章題目:創(chuàng)新互聯(lián)Python教程:如何用python處理數(shù)據(jù)
網(wǎng)頁網(wǎng)址:http://m.fisionsoft.com.cn/article/djhpchd.html


咨詢
建站咨詢
