我需要计算某一多指数主要标题的多指数小标题的数目。
This question is related to my previous question here: read_csv: Multiple Header Rows. Single header row has duplicates within it, but no column is duplicated when both header rows considered If that link doesn t pass, the search term on stackoverflow would be: "read_csv: Multiple Header Rows. Single header row has duplicates within it, but no column is duplicated when both header rows considered"
采用同样的样本目录:
Sample csv file:
Exp,2023-09-22,2023-09-22,2023-09-29,2023-10-06,2023-10-13
Code,A,B,A,A,A
Item,,,,,
260,1,8,17,31,42
270,2,9,18,32,43
280,3,10,19,33,44
290,4,11,20,34,45
300,5,12,21,35,46
And reading the csv into a data frame like this:
Gives Output:
print(df)
Exp 2023-09-22 2023-09-29 2023-10-06 2023-10-13
Code A B A A A
Item
270 2 9 18 32 43
280 3 10 19 33 44
290 4 11 20 34 45
300 5 12 21 35 46
Question: How do I count the number of "Code" entries for a given Exp heading? For example: How many Code entries are listed for Exp 2023-09-22 ? Answer: 2 (they are A and B ) How many Code entries are listed for Exp 2023-10-13 ? Answer: 1
令人非常赞赏的是,任何帮助掩盖了这一问题。
我曾尝试过各种镜头(df.columns[col_idx])和其他器具,但我没有看到任何东西。 关于可接受的解决办法,我要么用数字,如图2或图1,要么用我随后可以计算的姓名或价值清单(或无论它们是否认为)。 无论如何,这些法典要么是“A”要么是“B”,要么是“A”&”B”。