当前位置:网站首页>ValueError: color kwarg must have one color per data set. 9 data sets and 1 colors were provided
ValueError: color kwarg must have one color per data set. 9 data sets and 1 colors were provided
2022-06-26 00:04:00 【Falling ink painting snow】
About use pandas Medium read_csv() Read existing csv Data and analyze the data hist Show when histogram is drawn ValueError: color kwarg must have one color per data set. 9 data sets and 1 colors were provided Solutions for
1 Problem description
Because of practical needs , Store a one-dimensional list data obtained in the experiment , And read data from it for visual operation , For example, the topic "drawing histogram" , The example code is as follows :
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
a = np.array([1,2,3,4,5,5,5,5,6,3])# I wrote it myself
data = pd.Series(a)
print(data.shape)
print(data)
data.to_csv('xxx.csv')
b = pd.read_csv('xxx.csv')
print(b.shape)# For inspection
print(b.head(10))
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
data = b
plt.hist(data,color='b',bins=10)#bins Is the number of intervals to be divided
plt.show()
Some of the results are as follows :
(10,)
0 1
1 2
2 3
3 4
4 5
5 5
6 5
7 5
8 6
9 3
dtype: int32
(9, 2)
0 1
0 1 2
1 2 3
2 3 4
3 4 5
4 5 5
5 6 5
6 7 5
7 8 6
8 9 3
Error reporting hist On ,
ValueError: color kwarg must have one color per data set. 9 data sets and 1 colors were provided
2 Problem analysis
Because something went wrong , So I added some print functions to the above code , Results found , Store data to csv front , namely to_csv and read_csv The data structure has changed , Before storage yes (10,) The change of reading after storage becomes (9,2), The reason should appear here , Therefore, the above error report should change the original column data into [[1,2,3],[1,2,3]…] Multidimensional list form of , Therefore, the above error report appears , However, there is a problem with the structure after data reading , The reason is that when reading , The originally automatically generated index page is taken as a column of data , And the original first 0 Row data as a column field results in , So it needs to be studied again ,to_csv( ) and read_csv( ) Parameter settings in .
Detailed about read_csv() For parameter problems, please move to pandas.read_csv Sort out the usage of common parameters
3 Problem solving
Don't talk much , Directly solve the code , See the effect
a = np.array([1,2,3,4,5,5,5,5,6,3])
data = pd.Series(a)
print(data.shape)
print(data)
data.to_csv('xxx.csv')
b = pd.read_csv('xxx.csv',names=['rate'])
print(b.shape)
print(b.head(10))
aa = b.loc[:,'rate']
print(aa)
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
data = aa
plt.hist(data,color='b',bins=10)#bins Is the number of intervals to be divided
plt.show()
In fact, a column name is added to the data when reading , The metadata will not be used as column names because of some default parameters , meanwhile aa = b.loc[:,'rate'] Passed in as data hist among , This ensures that automatically added... Will not be passed in index
give the result as follows :
(10,)
0 1
1 2
2 3
3 4
4 5
5 5
6 5
7 5
8 6
9 3
dtype: int32
(10, 1)
rate
0 1
1 2
2 3
3 4
4 5
5 5
6 5
7 5
8 6
9 3
0 1
1 2
2 3
3 4
4 5
5 5
6 5
7 5
8 6
9 3
Name: rate, dtype: int64

边栏推荐
- 详细讲解局部变量、全局变量、静态变量三种类型
- Sword finger offer 48 Longest substring without duplicate characters
- Linking MySQL database with visual studio2015 under win10
- SSM整合学习笔记(主要是思路)
- Redis之常见问题
- Tensorflow中CSV文件数据读取
- About the swoole coroutine container
- Unsigned and signed vernacular
- My blog is 2 years old and 167 days old today. I received the pioneer blogger Badge_ Old bear passing by_ Sina blog
- Stop eating vitamin C tablets. These six fruits have the highest vitamin C content
猜你喜欢

Alipay payment interface sandbox environment test and integration into an SSM e-commerce project

推荐系统设计

SSM integrated learning notes (mainly ideas)

6.常用指令(上)v-cloak,v-once,v-pre

About Simple Data Visualization

WINCC与STEP7的仿真连接_过路老熊_新浪博客

Studio5k v28安装及破解_过路老熊_新浪博客

Literature research (IV): Hourly building power consumption prediction based on case-based reasoning, Ann and PCA

社交网络可视化第三方库igraph的安装

Common problems encountered when creating and publishing packages using NPM
随机推荐
Record some CF questions
博图软件中多重背景块的建立_过路老熊_新浪博客
postman如何测试需要登录的接口
文献调研(一):基于集成学习和能耗模式分类的办公楼小时能耗预测
How postman tests interfaces that require login
Using swiper to realize the rotation chart
Shredding Company poj 1416
STEP7 master station and remote i/o networking_ Old bear passing by_ Sina blog
请问可以不部署服务端实现图片上传吗?
Bit compressor [Blue Bridge Cup training]
PHP interprocess pass file descriptor
(转载)进程和线程的形象解释
Can I upload pictures without deploying the server?
Studio5k V28 installation and cracking_ Old bear passing by_ Sina blog
huibian
Implement const in Es5
《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)
Problems encountered in Doris operation and maintenance
树莓派开机发送热点进行远程登录
记录一些cf的题