[Python Study Notes]pd.read_csv()函数读取csv文件绘图

Posted 刘六六

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Python Study Notes]pd.read_csv()函数读取csv文件绘图相关的知识,希望对你有一定的参考价值。

image

\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
>>文件: pandas读取csv文件.py
>>作者: liu yang
>>博客: liuyang1.club
>>邮箱: liuyang0001@outlook.com
>>博客: www.cnblogs.com/liu66blog

\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import matplotlib
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# 定义要使用的字体,防止出现中文乱码
font=matplotlib.font_manager.FontProperties(fname=r"C:\\Windows\\Fonts\\Deng.ttf")

# 添加索引index_col=0 设置第一列为索引
df = pd.read_csv(u\'xxxx.csv\',encoding=\'utf-8\',index_col=0)

# print(df)
df_plot = df.plot(kind=\'bar\', rot=0)
# 设置标题头
plt.title(\'学生信息\', fontproperties=font)
# 第一个参数为数据排序,loc设置图例位置
plt.legend(loc=1)
plt.xlabel(\'姓名\', fontproperties=font)
plt.ylabel(\'\', fontproperties=font)
plt.xticks(fontproperties=font)
plt.yticks([y for y in range(0, 180, 10)],fontproperties=font)
# for x,y,z in zip(df.get(\'Height\')):
# plt.text(-0.2,df.get("Height")[0],\'%.0f\'%df.get("Height")[0], ha=\'center\', va=\'bottom\')
# plt.text(0,df.get("Score")[0],\'%.0f\'%df.get("Score")[0], ha=\'center\', va=\'bottom\')
# plt.text(0.15,df.get("Age")[0],\'%.0f\'%df.get("Age")[0], ha=\'center\', va=\'bottom\')
# df.to_csv(\'数据.csv\',encoding=\'utf-8\')
# 显示
plt.show()

以上是关于[Python Study Notes]pd.read_csv()函数读取csv文件绘图的主要内容,如果未能解决你的问题,请参考以下文章

[Python Study Notes]cpu信息

[Python Study Notes]计算器

[Python Study Notes]折线图绘制

[Python Study Notes]物体运动检测

[Python Study Notes]实现对鼠标控制

[Python Study Notes]水平直方图