anna17
(anna17)
May 11, 2024, 5:58am
1
Hello
This is CSV File Format (D:\csv_sample.csv)
Date,Tmperature
1981-01-01,20.7
1981-01-02,17.9
1981-01-03,18.8
1981-01-04,14.6
1981-01-05,15.8
1981-01-06,15.8
1981-01-07,15.8
1981-01-08,17.4
1981-01-09,21.8
1981-01-10,20
1981-01-11,16.2
1981-01-12,13.3
1981-01-13,16.7
1981-01-14,21.5
1981-01-15,25
1981-01-16,20.7
1981-01-17,20.6
1981-01-18,24.8
1981-01-19,17.7
1981-01-20,15.5
It is printed as below.
import pandas as pd
import numpy as np
data = pd.read_csv("D:\csv_sample.csv")
print(data)
==> Date Tmperature
0 1981-01-01 20.7
1 1981-01-02 17.9
2 1981-01-03 18.8
3 1981-01-04 14.6
4 1981-01-05 15.8
5 1981-01-06 15.8
6 1981-01-07 15.8
7 1981-01-08 17.4
8 1981-01-09 21.8
9 1981-01-10 20.0
10 1981-01-11 16.2
11 1981-01-12 13.3
12 1981-01-13 16.7
13 1981-01-14 21.5
14 1981-01-15 25.0
15 1981-01-16 20.7
16 1981-01-17 20.6
17 1981-01-18 24.8
18 1981-01-19 17.7
19 1981-01-20 15.5
I want to take only the temperature column value and convert it as shown below.
I want it printed in this form.
import pandas as pd
import numpy as np
data = pd.read_csv("D:\csv_sample.csv")
#@@#%$#$%%@#$%@ ?????? Convert Function Python
print(data)
==> [20.7 17.9 18.8 14.6 15.8 15.8 15.8 17.4 21.8 20 16.2 13.3 16.7 21.5 25 20.7 20.6 24.8 17.7 15.5]
[20.7 17.9 18.8 14.6 15.8 15.8 15.8 17.4 21.8 20 16.2 13.3 16.7 21.5 25 20.7 20.6 24.8 17.7 15.5]
Is there a Python function that leaves the csv file as is and converts it to the format above?
kknechtel
(Karl Knechtel)
May 11, 2024, 7:06am
2
Did you try data['Tmperature']
?
Notice it is not spelled properly in the data you show. The code must match what your file actually has.
anna17
(anna17)
May 11, 2024, 7:43am
4
csvfile.csv
==>Date,Tmperature
1981-01-01,20.7
1981-01-02,17.9
1981-01-03,18.8
1981-01-04,14.6
1981-01-05,15.8
1981-01-06,15.8
1981-01-07,15.8
1981-01-08,17.4
1981-01-09,21.8
1981-01-10,20
1981-01-11,16.2
1981-01-12,13.3
1981-01-13,16.7
1981-01-14,21.5
1981-01-15,25
1981-01-16,20.7
1981-01-17,20.6
1981-01-18,24.8
1981-01-19,17.7
1981-01-20,15.5
import pandas as pd
import numpy as np
data = pd.read_csv(“D:\csvfile.csv”)
print(data)
==>
Date Tmperature
0 1981-01-01 20.7
1 1981-01-02 17.9
2 1981-01-03 18.8
3 1981-01-04 14.6
4 1981-01-05 15.8
5 1981-01-06 15.8
6 1981-01-07 15.8
7 1981-01-08 17.4
8 1981-01-09 21.8
9 1981-01-10 20.0
10 1981-01-11 16.2
11 1981-01-12 13.3
12 1981-01-13 16.7
13 1981-01-14 21.5
14 1981-01-15 25.0
15 1981-01-16 20.7
16 1981-01-17 20.6
17 1981-01-18 24.8
18 1981-01-19 17.7
19 1981-01-20 15.5
print(data[“Tmperature”])
==>
0 20.7
1 17.9
2 18.8
3 14.6
4 15.8
5 15.8
6 15.8
7 17.4
8 21.8
9 20.0
10 16.2
11 13.3
12 16.7
13 21.5
14 25.0
15 20.7
16 20.6
17 24.8
18 17.7
19 15.5
Name: Tmperature, dtype: float64
====> BUT ------------
=> I want to take only the temperature column value and convert it as shown below.
I want it printed in this form.
[20.7 17.9 18.8 14.6 15.8 15.8 15.8 17.4 21.8 20 16.2 13.3 16.7 21.5 25 20.7 20.6 24.8 17.7 15.5]
Is there a Python function that leaves the csv file as is and converts it to the format above?
Question remains why, but simple .to_list() would do:
print(data['Tmperature'].to_list())