pandas的一些基础用法

栏目: 数据库 · 发布时间: 7年前

内容简介:首先我们导入一些‘业界标准’库Pandas 里有两种常用的结构,一种叫

首先我们导入一些‘业界标准’库

import pandas as pd
import numpy as np
import talib as ta
import matplotlib.pyplot as plt

Pandas 里有两种常用的结构,一种叫 DataFrame ,作为二维的一张表格;另一种叫 Series ,是一维数组。

DataFrame 取单行和单列得到的都是 Series 类型的对象。

追加数据

df = df.append(series, ignore_index=True)

获取最后一列数据

series = df.iloc[-1]

获取名为 close 的 column

series = df.close
或者
series = df['close']

取 series 中单个元素

close: float = series.close
close: float = series['close']

series 转 list

series.list()

series 转 np array

np_array = np.array(series)
或
np_array = np.array(df.close)
或
np_array = np.array(df['close'])

结合 talib 计算

ta.RSI(np.array(bars.close))

可视化

df = pd.DataFrame({
    'close': ... ,
    'open': ... ,
    'high': ... ,
    'low': ... ,
    'timestamp', ...
})

# figure 1
df.plot(x='timestamp', y=['close', 'high', 'low'])  # 展示 close high low 三个属性

# figure 2
df.plot(x='timestamp')  # 展示全部属性

# 展示上面两幅绘制过的图
plt.show()

Over


以上所述就是小编给大家介绍的《pandas的一些基础用法》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Web Security Testing Cookbook

Web Security Testing Cookbook

Paco Hope、Ben Walther / O'Reilly Media / 2008-10-24 / USD 39.99

Among the tests you perform on web applications, security testing is perhaps the most important, yet it's often the most neglected. The recipes in the Web Security Testing Cookbook demonstrate how dev......一起来看看 《Web Security Testing Cookbook》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

随机密码生成器
随机密码生成器

多种字符组合密码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具