Python数据处理pandas基本属性

Python数据处理pandas基本属性,第1张

# Series数据结构
import pandas as pd
import numpy as np

# Series数据结构
s1 = pd.Series(['a', 'b', 'c', 'd'], index=['一', '二', '三', '四'])
print(s1)
s2 = pd.Series({'a': 1, 'b': 2, 'c': 3, 'd': 4})  # 使用字典方法
print(s2)
print(s1.index)  # 打印索引
print(s1.values)  # 打印值
# DataFrame表格形式
df1 = pd.DataFrame(['a', 'b', 'c', 'd'])  # 一维
print(df1)
df2 = pd.DataFrame([['a', 'A'], ['b', 'B'], ['c', 'C'], ['d', 'D']])  # 二维 想象它是一个表 在np中输出的是一个二维数组 两者可以互用
print(df2)
df3 = pd.DataFrame(np.array([['a', 'A'], ['b', 'B'], ['c', 'C'], ['d', 'D']]), columns=['lowercase', 'uppercase'],
                   index=['一', '二', '三', '四'])
print(df3)

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/957005.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-18
下一篇 2022-06-10

发表评论

登录后才能评论

评论列表(0条)

保存