立即注册 登录
气象家园 返回首页

主啊的个人空间 https://bbs.06climate.com/?69999 [收藏] [复制] [分享] [RSS]

日志

pandas学习笔记,python数据科学手册

已有 108 次阅读2023-6-14 00:22



import pandas as pd

# series
# 带索引的一维数组
data = pd.Series([0.25,0.2,0.75,1.0])
print(data)

print("*"*60)
print(data.values)
print(data.index)

print(data[1])
print(data[1:3])

# 定义索引
data = pd.Series([0.25,0.2,0.75,1.0],
                 index=["a","b","c","d"])
print(data)
print(data["a"])
print("-"*60)
print(data.keys()) #字典方式查看索引
print(list(data.items())) #字典方式查看索引
data["e"] = 1 #增加数据
print(data)
# 切片

print("qiepiqna"*3)
print(data["a":"c"]) # 显示切片
print(data[0:2]) #前两行 # 隐示切片
print(data[(data > 0.3) & (data<0.8)])#掩码切片
print(data["a","e"]) #索引出来两个要素



# 字典方式创建
pp = {"a":12,
      "b":55,
      "c":4,
      "d":11
      }
pp = pd.Series(pp)
# 或者
pp = pd.Series({
        "a":12,
        "b":55,
        "c":4,
        "d":11
})
print(pp)
print(pp["b"])


# ------------------------
print("*"*60)
print("DataFrame")

# area
area_dict = {
    "calforia":12121,
    "floriad":54545,
    "illsjf":89797,
    "neww":85222,
    "teass":45698
}
area = pd.Series(area_dict)
print(area)


#population
po_dict = {
    "calforia":1,
    "floriad":2,
    "illsjf":3,
    "neww":4,
    "teass":5
}
population = pd.Series(po_dict)
print(population)

# dataframe
states = pd.DataFrame(
    {"population":population,
    "area":area}
)
print(states)
print(states.index)
print(states.columns)
print(states["area"])

# ----单个创建
dd = pd.DataFrame(population, columns=["population"])
print(dd)

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 立即注册

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

返回顶部