调用CSV文件并将文件中的百分数转换为float,以及计算列的平均数,方差

调用CSV文件并将文件中的百分数转换为float,以及计算列的平均数,方差

在这里插入图片描述
CSV文件就长这个亚子。

import numpy as py
import pandas as pd
import matplotlib.pyplot as plt
#sep=';',是因为CSV文件是以;为分隔符的
history = pd.read_csv(r'C:\Users\Administrator\Desktop\history.csv',sep=';',index_col = 'date')
history.head(3)

在这里插入图片描述

#查看数据类型
print(history.dtypes)

在这里插入图片描述

#将文件中某一列的object格式转换为float模式,不然字符串是无法计算的
history['Emerging'] = history['Emerging'].str.strip('%').astype(float)/100
print(history.dtypes)

在这里插入图片描述

#计算某一列的平均数
history.Emerging.mean()
#计算某一列的第10分位数和第90分位数
[history.Emerging.quantile(i) for i in [0.1,0.9]]
#继续将另外两列数据转换一下格式
history['Relative Value'] = history['Relative Value'].str.strip('%').astype(float)/100
history['Fixed Income Arbitrage'] = history['Fixed Income Arbitrage'].str.strip('%').astype(float)/100
history['Relative Value'].plot()
history['Fixed Income Arbitrage'].plot()

在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值