data ['state']由状态组成。 data ['new']由关闭和打开组成。 我只想在新列中打开以与状态列分组。
'data.groupby(['State','new'])。size()。unstack()。fillna(0).sort_values('close',ascending = False)'
output:
new close open
State
Georgia 12.185120 15.473888
Florida 11.775044 7.543520
California 9.314587 11.798839
Illinois 7.908612 5.609284
Pennsylvania 6.444054 3.868472
Tennessee 5.623902 9.090909
Michigan 5.389572 4.448743
Washington 4.393673 4.448743
Maryland 3.690685 2.901354
Colorado 3.397774 4.255319
New Jersey 3.280609 3.675048
Indiana 2.929115 1.740812
Massachusetts 2.929115 2.127660
Texas 2.870533 4.255319
Virginia 2.870533 2.127660
Oregon 2.108963 2.514507
Minnesota 1.698887 0.773694
Mississippi 1.347393 3.094778
Alabama 0.995899 1.740812
Utah 0.937317 1.160542
South Carolina 0.878735 0.580271
Arizona 0.820152 1.160542
District Of
Columbia 0.820152 0.386847
Louisiana 0.702988 0.193424
New Mexico 0.644405 0.773694
Connecticut 0.527241 0.580271
West Virginia 0.468658 0.580271
New Hampshire 0.468658 0.773694
Delaware 0.468658 0.773694
Arkansas 0.351494 0.000000
New York 0.351494 0.000000
Kentucky 0.234329 0.580271
Maine 0.175747 0.386847
North Carolina 0.175747 0.000000
Missouri 0.175747 0.193424
Ohio 0.175747 0.000000
Vermont 0.117165 0.193424
District of
Columbia 0.058582 0.000000
Rhode Island 0.058582 0.000000
Iowa 0.058582 0.000000
Kansas 0.058582 0.193424
Nevada 0.058582 0.000000
Montana 0.058582 0.000000
I want sort value by open.can anyone help me.
答案 0 :(得分:1)
is_open = data['new'] == 'open' # Returns dataframe with true/false
open_data = data[is_open] # Shows entry if is_data entry is true