logo
down
shadow

Use idxmax for indexing in pandas


Use idxmax for indexing in pandas

By : Israr Taj
Date : November 17 2020, 11:55 AM
I wish did fix the issue. You should iterate over the series and access the index and col name to set the values:
code :
In [30]:

for items in df.idxmax().iteritems():
    print(items)
    df.loc[items[1], items[0]] = -9.9
df
('one', 'b')
('two', 'd')
Out[30]:
    one  two
a  1.40  NaN
b -9.90 -4.5
c   NaN  NaN
d  0.75 -9.9


Share : facebook icon twitter icon
Pandas idxmax() get column name corresponding to max value in row

Pandas idxmax() get column name corresponding to max value in row


By : Lee Twito
Date : March 29 2020, 07:55 AM
This might help you IIUC, you can use axis=1 in idxmax:
code :
policy = Q_df.idxmax(axis=1)

(0, 0)    (1, 0)
(0, 1)    (0, 2)
(0, 2)    (2, 2)
(1, 0)    (1, 2)
(1, 1)    (0, 1)
(1, 2)    (2, 2)
(2, 0)    (1, 0)
(2, 1)    (0, 1)
(2, 2)    (0, 2)
dtype: object
Pandas Idxmax on a date-value DataFrame

Pandas Idxmax on a date-value DataFrame


By : Patrick Woo-Sam
Date : March 29 2020, 07:55 AM
Hope that helps Given this DataFrame: , Because it should be:
code :
df.Value.idxmax()
Pandas find idxmax() between range

Pandas find idxmax() between range


By : Do Phong Tran
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , You can use iloc for seelct all columns without first 5 by indexing:
code :
N = 5
findValue = (df['Current'].iloc[N:] > 0.01).idxmax()
print (findValue)
2018-09-01 00:06
m1 = df['Current'] > 0.01
m2 = np.arange(len(df)) >= 5
findValue = (m1 & m2).idxmax()
print (findValue)
2018-09-01 00:06
findValue = (df['Current'].loc['2018-09-01 00:05':] > 0.01).idxmax()
print (findValue)
2018-09-01 00:06:00

m1 = df['Current'] > 0.01
m2 = df.index >= '2018-09-01 00:05'
findValue = (m1 & m2).idxmax()
print (findValue)
2018-09-01 00:06:00
m1 = df['Current'] > 5.01
m2 = np.arange(len(df)) >= 5
findValue = (m1 & m2).idxmax()

print (findValue)
2018-09-01 00:00:00
m1 = df['Current'] > 5.01
m2 = np.arange(len(df)) >= 5
findValue = next(iter(df.index[m1 & m2]), 'no exist')

print (findValue)
no exist
pandas: idxmax for k-th largest

pandas: idxmax for k-th largest


By : user3632814
Date : March 29 2020, 07:55 AM
this one helps. My own solution is not the prettiest, but does it's job and works fast:
code :
for i in range(7):
    p[f'{i}k'] = p[[0,1,2,3,4,5,6]].idxmax(axis=1)
    p[f'{i}k_v'] = p[[0,1,2,3,4,5,6]].max(axis=1)

    for x in range(7):
        p[x] = np.where(p[x]==p[f'{i}k_v'], np.nan, p[x])
Pandas: Idxmax, best n results

Pandas: Idxmax, best n results


By : Chris Barry
Date : March 29 2020, 07:55 AM
With these it helps I'm doing principal component analysis and have the following type of components result: , You can use the nlargest method.
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org