import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('ggplot')
datos_0 = pd.DataFrame([[0.5, 0.55, 0.7, 0.25, 0.56, 0.65, 0.39, 0.58, 0.62, 0.45],
[321, 475, 550, 299, 365, 700, 323, 457, 369, 457]])
print datos_0
0 1 2 3 4 5 6 7 8 \ 0 0.5 0.55 0.7 0.25 0.56 0.65 0.39 0.58 0.62 1 321.0 475.00 550.0 299.00 365.00 700.00 323.00 457.00 369.00 9 0 0.45 1 457.00
datos_0 = datos_0.T
print datos_0
0 1 0 0.50 321.0 1 0.55 475.0 2 0.70 550.0 3 0.25 299.0 4 0.56 365.0 5 0.65 700.0 6 0.39 323.0 7 0.58 457.0 8 0.62 369.0 9 0.45 457.0
datos_1 = pd.DataFrame({'coef_escorrentia': [0.5, 0.55, 0.7, 0.25, 0.56, 0.65, 0.39, 0.58, 0.62, 0.45],
'precipitacion': [321, 475, 550, 299, 365, 700, 323, 457, 369, 457]})
print datos_1
coef_escorrentia precipitacion 0 0.50 321 1 0.55 475 2 0.70 550 3 0.25 299 4 0.56 365 5 0.65 700 6 0.39 323 7 0.58 457 8 0.62 369 9 0.45 457
resultado = datos_1.describe()
print resultado
coef_escorrentia precipitacion count 10.000000 10.000000 mean 0.525000 431.600000 std 0.133437 124.362552 min 0.250000 299.000000 25% 0.462500 333.500000 50% 0.555000 413.000000 75% 0.610000 470.500000 max 0.700000 700.000000
media_esc = resultado.loc['mean', 'coef_escorrentia']
print media_esc
0.525
p3_1 = datos_1.loc[2, 'precipitacion']
print p3_1
550.0
p3_2 = datos_1.iloc[2, 1]
print p3_2
550.0
mean_prec_4 = np.mean(datos_1.loc[0:4, 'precipitacion'])
print mean_prec_4
402.0
c_e = datos_1['coef_escorrentia']
prep = datos_1['precipitacion']
print c_e
print prep
0 0.50 1 0.55 2 0.70 3 0.25 4 0.56 5 0.65 6 0.39 7 0.58 8 0.62 9 0.45 Name: coef_escorrentia, dtype: float64 0 321 1 475 2 550 3 299 4 365 5 700 6 323 7 457 8 369 9 457 Name: precipitacion, dtype: int64
area = 600
volumen_anual = (c_e * prep / 1000 * area * 10e6) / 10e6 # hectometros cubicos
print volumen_anual
0 96.300 1 156.750 2 231.000 3 44.850 4 122.640 5 273.000 6 75.582 7 159.036 8 137.268 9 123.390 dtype: float64
volumen_total = np.sum(volumen_anual)
print volumen_total
1419.816
plt.figure('volumen_anual')
plt.plot(volumen_anual)
plt.show()
plt.figure('relacion_variables')
plt.scatter(c_e, prep, marker='o')
plt.xlabel('$c_e$')
plt.ylabel('precipitacion $(mm)$')
plt.show()
c = 0
for val in prep:
if val > 500:
c += 1 # c = c + 1
print c
2
clasificacion_anual = pd.Series(np.zeros(len(prep)))
for i, val in enumerate(volumen_anual):
if val < 50:
clasificacion_anual[i] = 1
elif 50 <= val < 100: # elif val >= 50 and val < 100
clasificacion_anual[i] = 2
elif 100 <= val < 150:
clasificacion_anual[i] = 3
elif val >= 150:
clasificacion_anual[i] = 4
print clasificacion_anual
0 2.0 1 4.0 2 4.0 3 1.0 4 3.0 5 4.0 6 2.0 7 4.0 8 3.0 9 3.0 dtype: float64