This is my code.I will try to read file and find the maximum temperature value(11th column)
import pandas as pd
fn = 'Excel.xlsx'
df = pd.read_excel(fn, header=None)
df1 = df.iloc[:,11:12]
m1 = df.iloc[:,11:12].max()
print (m1)
What I got is not want I wanted
python n0.py
11 Value
dtype: object
I will show how the 11-th column looks like
0 Value
1 18.71
2 20.86
3 18.37
4 12.3
5 5.54
6 3.96
7 8.33
8 12.23
9 11.02
10 4.18
11 7.62
12 15.06
13 20
14 20.39
15 18.26
16 14.54
17 3.81
18 0.93
19 7.74
20 12.42
21 6.59
22 0.12
23 8.32
24 16.82
25 19.46
26 11.8
27 6.25
28 1.96
29 17.13
...
756 15.59
757 6.82
758 7.48
759 14.99
760 17.61
761 19.48
762 16.8
763 9.65
764 1.63
765 9.26
766 16.25
767 24.85
768 14.08
769 0.11
770 6.56
771 12.75
772 21.94
773 20.57
774 17.97
775 12.73
776 6.16
777 9.12
778 19.03
779 17.39
780 14.06
781 1.76
782 8.25
783 17.41
784 20.61
785 20.73
From these values 24.85 would be the max and it is on 767 position. I have not worked with pandas lately but this was supposed to be simple job. Where is my mistake? Should I use idmax or something else?
First convert column to numeric
by to_numeric
with errors='coerce'
:
and then need for 12
th column:
max = pd.to_numeric(df.iloc[:,11], errors='coerce').max()
and for 11
th need 10
, because python counts from 0
:
max = pd.to_numeric(df.iloc[:,10], errors='coerce').max()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.