【学习笔记】大数据与机器学习— Pandas

[huayang]

导入方式

import numpy as np
import pandas as pd

数据读取

csv文件

import numpy as np
import pandas as pd

fpath = open("ratings.csv")

ratings = pd.read_csv(fpath)

print(ratings)

使用head()即可返回前几行数据

import numpy as np
import pandas as pd

fpath = open("ratings.csv")

ratings = pd.read_csv(fpath)

print(ratings.head())

使用shape查看数据形状,返回(行数,列数)

import numpy as np
import pandas as pd

fpath = open("ratings.csv")

ratings = pd.read_csv(fpath)

print(ratings.shape)

使用columns查看列名列表

import numpy as np
import pandas as pd

fpath = open("ratings.csv")

ratings = pd.read_csv(fpath)

print(ratings.columns)

使用index查看索引列

import numpy as np
import pandas as pd

fpath = open("ratings.csv")

ratings = pd.read_csv(fpath)

print(ratings.index)

使用dtypes查看每列数据类型

import numpy as np
import pandas as pd

fpath = open("ratings.csv")

ratings = pd.read_csv(fpath)

print(ratings.dtypes)

读取txt文件(需要自己指定分隔符列名)

import numpy as np
import pandas as pd

fpath = open("access_pvuv.txt")

asd = pd.read_csv(fpath,sep="\t",header=None,names=['qwe','asd','zxc'])

print(asd)#sep 指定列的分隔符 ,因为没有标题行所以header为none,names设定列名

读取excel文件

需要安装openpyxl这个库

import numpy as np
import pandas as pd

asd =  pd.read_excel('access_pvuv.xlsx')

print(asd)

pandas数据结构

Series

series是一种类似于一维数组的对象,他由一组数据(不同数据类型)
以及一组与之相关的数据标签(即索引)组成

仅有数据列表即可产生最简单的series

import numpy as np
import pandas as pd

s = pd.Series(['1','a','5.2','7'])
print(s)

values元素值的列表

dataframe:二位数据,整个表格,多行多列

[/huayang]

==>转载请注明来源哦<==

评论

  1. 头像
    muzz
    Windows Chrome
    6月前
    2021-8-13 12:01:14

    ll

  2. 头像
    李四
    Windows Chrome
    6月前
    2021-8-12 22:16:27

    haha

  3. 头像
    张三
    Windows Firefox
    7月前
    2021-7-14 21:31:36

    康康

  4. 头像
    liunano
    Windows Chrome
    7月前
    2021-7-01 13:13:34

    哈哈

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇