ValueError:|ValueError: arrays must all be same length
【ValueError:|ValueError: arrays must all be same length】d={ 'NUM' : range(3),
'C' : ['c1','c2','c3'],
'D' : ['d1','d2','d3','d4'],
'E' : ['e1','e2','e3'],
'B' : ['b1','b2','b3']}
会报错,因为会把key转换成列名,后面的数组转化为对应的值,必须长度一样,这里D多了
解决方法:
pd.DataFrame.from_dict(d, orient='index')
但是这样在to_excel的时候文件里只有values没有key
我希望把key也保存在文件里
df = df.reset_index().rename(columns={'index': 'key'}) 就可以了
pd.read_csv(路径,skiprows=9,nrows=10),忽略前9行,往下读10行
推荐阅读
- Java8|Java8 Collections.sort()及Arrays.sort()中Lambda表达式及增强版Comparator的使用
- MQ 简介
- Arrays.sort()源码分析与典型实现例子
- Android|Android Studio 删除多余的module Mac 和 Cause: buildOutput.apkData must not be null
- 多层LSTM神经网络),出现ValueError: Input 0 is incompatible with layer lstm_21: expected ndim=3, found错误
- ValueError: Error when checking input: expected input_image_meta to have shape (None, 14) but got ar
- ValueError: Error when checking : expected input_1 to have 4 dimensions, but got array with shape
- Python3|Python3 TypeError: only size-1 arrays can be converted to Python scalars
- maven的pom文件报错( must be "pom" but is "jar")
- python|ValueError: Input contains NaN, infinity or a value too large for dtype('float32'64). 一般处理方式