my_code_base.core.pandas_utils¶
Module Contents¶
- my_code_base.core.pandas_utils.grid_dataframe(points, vals, xi, export_grid=False)[source]¶
Bin the values with points coordinates by the given target coordinates xi and put the average of each bin onto the target grid.
- Parameters:
Example
>>> pytest.skip() >>> df = pd.DataFrame({'lon': np.linspace(0, 40, 100), >>> 'lat': np.sin(np.linspace(0, 3, 100))*10 + 40, >>> 'data': np.linspace(240,200,100)}) >>> xi = np.linspace(-5, 45, 40) >>> yi = np.linspace(35, 53, 50) >>> gridded = grid_dataframe((df.lon, df.lat), df.data, (xi, yi)) >>> plt.pcolormesh(xi, yi, gridded, shading='auto', cmap='Greens_r') >>> plt.scatter(df.lon, df.lat, c=df.data, marker='.', lw=.75, cmap='Reds', label='raw data') >>> plt.xlabel('Longitude') >>> plt.ylabel('Latitude') >>> plt.legend() >>> plt.show()