I'm learning how to use Pandas and Matplotlib and I'm doing an analysis based on average monthly precipitation and temperature data for a city. I originally have these data horizontally, that is, I have a Dataset of 1 row x 24 columns. Then using the command df.T
I changed the columns to rows, but I want to make two new columns, one called "Precipitation" containing the values from "enepreci30a" to "dicpreci30a" and another called "Temperature" containing the values from "enetemp30a" to "dicttemp30a", that is, I am left with the following:
Mes Precipitación (mm) Temperatura (°C)
ene 63.2 22.4
feb 81.4 22.7
mar 129.1 22.7
abr 170.7 22.4
may 213.5 22.6
jun 149.4 22.9
jul 133.1 23.1
ago 139.7 23.1
sep 181.8 22.4
oct 226.7 21.8
nov 158.9 21.8
dic 104.8 21.9
This is what I have done so far:
precipitación_y_temperatura_promedio_Medellín_2=precipitación_y_temperatura_promedio_Medellín.drop(['Código','Departamento','Municipio','Latitud','Coordenada Latitud','Longitud','Coordenada Longitud','Altitud (msnm)'],axis=1)
precipitación_y_temperatura_promedio_Medellín_2.info()
print(precipitación_y_temperatura_promedio_Medellín_2)
precipitación_y_temperatura_promedio_Medellín_2.T
<class 'pandas.core.frame.DataFrame'>
Int64Index: 1 entries, 382 to 382
Data columns (total 24 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 enepreci30a 1 non-null float64
1 febpreci30a 1 non-null float64
2 marpreci30a 1 non-null float64
3 abrpreci30a 1 non-null float64
4 maypreci30a 1 non-null float64
5 junpreci30a 1 non-null float64
6 julpreci30a 1 non-null float64
7 agopreci30a 1 non-null float64
8 seppreci30a 1 non-null float64
9 octpreci30a 1 non-null float64
10 novpreci30a 1 non-null float64
11 dicpreci30a 1 non-null float64
12 enetemp30a 1 non-null float64
13 febtemp30a 1 non-null float64
14 martemp30a 1 non-null float64
15 abrtemp30a 1 non-null float64
16 maytemp30a 1 non-null float64
17 juntemp30a 1 non-null float64
18 jultemp30a 1 non-null float64
19 agotemp30a 1 non-null float64
20 septemp30a 1 non-null float64
21 octtemp30a 1 non-null float64
22 novtemp30a 1 non-null float64
23 dictemp30a 1 non-null float64
dtypes: float64(24)
memory usage: 280.0 bytes
enepreci30a febpreci30a marpreci30a abrpreci30a maypreci30a \
382 63.2 81.4 129.1 170.7 213.5
junpreci30a julpreci30a agopreci30a seppreci30a octpreci30a ... \
382 149.4 133.1 139.7 181.8 226.7 ...
martemp30a abrtemp30a maytemp30a juntemp30a jultemp30a agotemp30a \
382 22.7 22.4 22.6 22.9 23.1 23.1
septemp30a octtemp30a novtemp30a dictemp30a
382 22.4 21.8 21.8 21.9
[1 rows x 24 columns]
382
enepreci30a 63.2
febpreci30a 81.4
marpreci30a 129.1
abrpreci30a 170.7
maypreci30a 213.5
junpreci30a 149.4
julpreci30a 133.1
agopreci30a 139.7
seppreci30a 181.8
octpreci30a 226.7
novpreci30a 158.9
dicpreci30a 104.8
enetemp30a 22.4
febtemp30a 22.7
martemp30a 22.7
abrtemp30a 22.4
maytemp30a 22.6
juntemp30a 22.9
jultemp30a 23.1
agotemp30a 23.1
septemp30a 22.4
octtemp30a 21.8
novtemp30a 21.8
dictemp30a 21.9
It occurs to me that the easiest way to do it is like this:
In this way you are dividing your original DataFrame into two DataFrames of 12 rows each, in fact this question was answered in the following post Split pandas dataframe in two if it has more than 10 rows