目录

行和列 shape()

平均值 mean()

 统计次数 value_counts()

移位 shift()

求和 add() 与 radd()

求差 sub() 与 rsub()

乘法 mul() 与 rmul()

除法 div() 与 rdiv()

余数 mod() 与 rmod()

指数pow() 与 rpow()

Pandas 数据分析 - 学习笔记目录


行和列 shape()

// rows 
df.shape[0]

// columns 
df.shape[1]

平均值 mean()

import pandas as pd

data = {
    "hello": [1, 2, 3, 4, 5, 6, 7, 8, 9],
    "world": [100, 200, 300, 400, 500, 600, 700, 800, 900]
}
i = ["YYDataV1", "YYDataV2", "YYDataV3", "YYDataV4", "YYDataV5",
     "YYDataV6", "YYDataV7", "YYDataV8", "YYDataV9"]
df = pd.DataFrame(data, index=i)

# 平均值,默认按行计算
print(df.mean())
# 平均值,按列计算
print(df.mean(1))

 统计次数 value_counts()

import pandas as pd

data = [100, 200, 300, 400, 500, 600, 700, 900, 900]

i = ["YYDataV1", "YYDataV2", "YYDataV3", "YYDataV4", "YYDataV5",
     "YYDataV6", "YYDataV7", "YYDataV8", "YYDataV9"]
df = pd.DataFrame(data, index=i)

# 统计次数
df = df.value_counts()
print(df)

移位 shift()

import pandas as pd

data = [100, 200, 300, 400, 500, 600, 700, 900, 900]

i = ["YYDataV1", "YYDataV2", "YYDataV3", "YYDataV4", "YYDataV5",
     "YYDataV6", "YYDataV7", "YYDataV8", "YYDataV9"]
df = pd.DataFrame(data, index=i)

print(df)
# 乾坤大挪移,移位
df = df.shift(2)
print(df)

求和 add() 与 radd()

import pandas as pd

data = {0: [100, 200, 300, 400, 500, 600, 700, 800, 900],
        1: [10, 20, 30, 40, 50, 60, 70, 80, 90]
        }

i = ["YYDataV1", "YYDataV2", "YYDataV3", "YYDataV4", "YYDataV5",
     "YYDataV6", "YYDataV7", "YYDataV8", "YYDataV9"]
df = pd.DataFrame(data, index=i)

# 求和
result = df[0].add(df[1])
print(result)

 

求差 sub() 与 rsub()

import pandas as pd

data = {0: [100, 200, 300, 400, 500, 600, 700, 800, 900],
        1: [10, 20, 30, 40, 50, 60, 70, 80, 90]
        }

i = ["YYDataV1", "YYDataV2", "YYDataV3", "YYDataV4", "YYDataV5",
     "YYDataV6", "YYDataV7", "YYDataV8", "YYDataV9"]
df = pd.DataFrame(data, index=i)

# 求差
result = df[0].sub(df[1])
print(result)

 

乘法 mul() 与 rmul()

import pandas as pd

data = {0: [100, 200, 300, 400, 500, 600, 700, 800, 900],
        1: [10, 20, 30, 40, 50, 60, 70, 80, 90]
        }

i = ["YYDataV1", "YYDataV2", "YYDataV3", "YYDataV4", "YYDataV5",
     "YYDataV6", "YYDataV7", "YYDataV8", "YYDataV9"]
df = pd.DataFrame(data, index=i)

# 乘法
result = df[0].mul(df[1])
print(result)

除法 div() 与 rdiv()

import pandas as pd

data = {0: [100, 200, 300, 400, 500, 600, 700, 800, 900],
        1: [10, 20, 30, 40, 50, 60, 70, 80, 90]
        }

i = ["YYDataV1", "YYDataV2", "YYDataV3", "YYDataV4", "YYDataV5",
     "YYDataV6", "YYDataV7", "YYDataV8", "YYDataV9"]
df = pd.DataFrame(data, index=i)

# 除法
result = df[0].div(df[1])
print(result)

余数 mod() 与 rmod()

import pandas as pd

data = {0: [100, 200, 300, 400, 500, 600, 700, 800, 900],
        1: [10, 20, 30, 40, 50, 60, 70, 80, 90]
        }

i = ["YYDataV1", "YYDataV2", "YYDataV3", "YYDataV4", "YYDataV5",
     "YYDataV6", "YYDataV7", "YYDataV8", "YYDataV9"]
df = pd.DataFrame(data, index=i)

# 求余数
result = df[0].mod(3)
print(result)

 

指数pow() 与 rpow()

import pandas as pd

data = {0: [100, 200, 300, 400, 500, 600, 700, 800, 900],
        1: [10, 20, 30, 40, 50, 60, 70, 80, 90]
        }

i = ["YYDataV1", "YYDataV2", "YYDataV3", "YYDataV4", "YYDataV5",
     "YYDataV6", "YYDataV7", "YYDataV8", "YYDataV9"]
df = pd.DataFrame(data, index=i)

# 求指数
result = df[0].pow(2)
print(result)

Pandas 数据分析 - 学习笔记目录

Pandas 数据分析 - 学习笔记目录_YYDataV的博客-CSDN博客

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐