所以我查看了一下stackoverflow,覺得非常類似的問題已經被問到,但是我無法完全解決這些問題的答案(對不起!)。使用循環或列表創建變量。動態循環不好?
從其他線程,我收集的是, 1)動態循環不好 2)列表理解或字典可能幫助我?
我想
grant1 = median(df.query('income < 25000')['grant']
grant2 = median(df.query('income > 25000 and income < 50000')['grant']
grant3 = median(df.query('income > 50000 and income < 75000')['grant']
grant4 = ...
grant5 = ...
funding1 = median(df.query('income < 25000')['funding']
funding2 = median(df.query('income > 25000 and income < 50000')['funding']
funding3 = median(df.query('income > 50000 and income < 75000')['funding']
funding4 = ...
funding5= ...
排序的我想要做什麼方面,我想在這裏做
source = ['grant', 'funding']
for x in source:
x1 = median(df.query('income < 25000')['x']
x2 = median(df.query('income > 25000 and income < 50000')['x']
x3 = ....
x4 = .....
任何建議或混亂結束了?
謝謝!
儘管你從未提到過這個(?),它看起來很像你使用的「pandas」,在這種情況下,有一些更好的方法來解決這個問題。 – DSM