我有一个像这样的熊猫数据框
0 1 2 3 4 5 6 7 8 90 0 0 0 0 0 0 0 0 01 0 0 0 0 0 0 0 0 02 0 0 0 0 0 0 0 0 03 0 0 0 0 0 0 0 0 04 0 0 0 0 0 0 0 0 05 0 0 0 0 0 0 0 0 0
在“-”上分割一列后,将自动生成列名0至9
原始df和拆分的代码
df = DataFrame(data, columns = ['id', 'sequence'])
print(df.sequence.str.split("-", expand=True))
df上的示例序列列为'0-0-0-0-0-0-0-0-0-0-0-0'
我如何重命名列名?
我想计算每列中出现0的次数,我该怎么办?
我尝试过基于df[df.education == '9th'].count()
的类似打印Python Pandas Counting the Occurrences of a Specific value的操作,但是我没有适当的列名,而且我不确定该怎么做。
请您帮忙。
您尝试过吗?df.rename(columns = {“ A”:“ NewName”,“ B”:“ NewName”})