Created
January 8, 2020 14:48
-
-
Save jainxy/7c626bb5b7ebf067b365a44d103d3223 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import pandas as pd\n", | |
"import numpy as np\n", | |
"import os, glob" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"data_root = 'resatelliteraindataforicici/'\n", | |
"data_rain_root = 'resatelliteraindataforicici_rain/'\n", | |
"save_root = 'resatelliteraindataforicici/out/'\n", | |
"csv_files = glob.glob(os.path.join(data_root,'*.csv'))\n", | |
"csv_files_rain = glob.glob(os.path.join(data_rain_root,'*.csv'))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def get_df_from_csv(filepath, save_res = False):\n", | |
" filename = os.path.basename(filepath)\n", | |
" name,ex = os.path.splitext(filename)\n", | |
"# loc = name.split('_')[0]\n", | |
" data = pd.read_csv(filepath, index_col=0, parse_dates=True)\n", | |
" data_max = data.resample('D').max().round(2)\n", | |
" data_max.columns = ['RH_max','T_max']\n", | |
" data_min = data.resample('D').min().round(2)\n", | |
" data_min.columns = ['RH_min','T_min']\n", | |
" data_ = pd.concat((data_min,data_max),axis=1)\n", | |
" data_ = data_.iloc[:,[0,2,1,3]]\n", | |
"# data['date'] = data.index.date\n", | |
" globals()[name] = data_\n", | |
" \n", | |
" if save_res:\n", | |
" filename_out = '_'.join(name.split('_')[:2]) + ex\n", | |
" filepath_out = os.path.join(save_root, filename_out)\n", | |
" if not os.path.exists(save_root):\n", | |
" os.makedirs(save_root)\n", | |
" data_.to_csv(filepath_out, index_label='Date')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"for filepath in csv_files:\n", | |
" get_df_from_csv(filepath, save_res=True)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"for filepath in csv_files_rain:\n", | |
" filename = os.path.basename(filepath)\n", | |
" name,ex = os.path.splitext(filename)\n", | |
" data = pd.read_csv(filepath, index_col=0, parse_dates=True).round(3)\n", | |
" globals()[name] = data" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 19, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"Kamuthi_weather = Kamuthi_weather_revised1.join(Kamuthi)\n", | |
"Aruppukottai_weather = Aruppukottai_weather_revised1.join(Aruppukottai)\n", | |
"Kovilpatti_weather = Kovilpatti_weather_revised1.join(Kovilpatti)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 20, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"Kamuthi_weather.to_csv('resatelliteraindataforicici/Kamuthi_weather.csv', index_label='Date')\n", | |
"Aruppukottai_weather.to_csv('resatelliteraindataforicici/Aruppukottai_weather.csv', index_label='Date')\n", | |
"Kovilpatti_weather.to_csv('resatelliteraindataforicici/Kovilpatti_weather.csv', index_label='Date')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment