Data handling - Monthly Flow

Note: The explanation of the code is generated with the assistance of AI Importing Libraries import pandas as pd import matplotlib.pyplot as plt pandas (pd): A powerful Python library for data manipulation and analysis. It provides data structures and functions to efficiently handle structured data, including tabular data such as spreadsheets and SQL tables. matplotlib.pyplot (plt): A Python plotting library that provides a MATLAB-like interface for creating a variety of charts, including line plots, scatter plots, histograms, and more. Loading the CSV File file_path = 'discharge_ai.csv' # Replace with the path to your CSV file df = pd.read_csv(file_path) pd.read_csv(file_path): This function reads a CSV file into a DataFrame. The DataFrame is a two-dimensional labeled data structure with columns of potentially different types. It is similar to an Excel spreadsheet or SQL table, or a dictionary of Series objects. Displaying the First Few Rows of the DataFrame print(df.head()) df.head(): This method returns the first n rows for the object based on position. It is useful for quickly testing if your object has the right type of data in it. By default, it returns the first 5 rows. Converting the ‘Date’ Column to Datetime Format df['Date'] = pd.to_datetime(df['Date']) pd.to_datetime(): This method converts various types of date formats into a standardized datetime format. It is useful for handling date and time data in a consistent manner. Setting the ‘Date’ Column as the Index df.set_index('Date', inplace=True) df.set_index(‘Date’, inplace=True): This method sets the ‘Date’ column as the index of the DataFrame. This allows for efficient data manipulation and analysis based on the date. Checking for Missing Values print(df.isna().sum()) df.isna(): This method returns a boolean DataFrame showing whether each element is missing (NaN) or not. .sum(): This method returns the sum of the boolean values, effectively counting the number of missing values. Handling Missing Values (Forward Fill) df.fillna(method='ffill', inplace=True) df.fillna(): This method fills missing values in the DataFrame. It can be used to fill missing values with a specific value or to forward fill missing values. method=‘ffill’: This method fills missing values by propagating the last valid observation forward. inplace=True: This parameter modifies the DataFrame in place, meaning it changes the original DataFrame. Resampling the Data to Calculate Monthly Averages monthly_avg = df.resample('M').mean() df.resample(‘M’): This method resamples the DataFrame by grouping it by a specified period. In this case, it groups the data by months. .mean(): This method calculates the mean of the resampled data. Displaying the Monthly Averages print(monthly_avg.head()) monthly_avg.head(): This method returns the first n rows for the object based on position. It is useful for quickly testing if your object has the right type of data in it. By default, it returns the first 5 rows. Plotting the Monthly Averages plt.figure(figsize=(10, 6)) plt.plot(monthly_avg.index, monthly_avg['Discharge'], marker='o', linestyle='-') plt.title('Monthly Average River Discharge') plt.xlabel('Date') plt.ylabel('Discharge (cubic meters per second)') plt.grid(True) plt.show() plt.figure(figsize=(10, 6)): This method creates a new figure with the specified size. plt.plot(): This method creates a line plot of the data. plt.title(): This method sets the title of the plot. plt.xlabel() and plt.ylabel(): These methods set the labels for the x and y axes. plt.grid(True): This method adds a grid to the plot. plt.show(): This method displays the plot. Full Script import pandas as pd import matplotlib.pyplot as plt from datetime import datetime # Load the CSV file file_path = 'discharge_ai.csv' df = pd.read_csv(file_path) # Define a function to convert the 'Date' column to datetime format def convert_date(df): df['Date'] = pd.to_datetime(df['Date']) return df # Define a function to set the 'Date' column as the index def set_index(df): df.set_index('Date', inplace=True) return df # Define a function to check for missing values def check_missing(df): print(df.isna().sum()) return df # Define a function to handle missing values def handle_missing(df): df.fillna(method='ffill', inplace=True) return df # Define a function to resample the data to calculate monthly averages def resample_data(df): monthly_avg = df.resample('M').mean() return monthly_avg # Define a function to plot the monthly averages def plot_data(monthly_avg): plt.figure(figsize=(10, 6)) plt.plot(monthly_avg.index, monthly_avg['Discharge'], marker='o', linestyle='-') plt.title('Monthly Average River Discharge') plt.xlabel('Date') plt.ylabel('Discharge (cubic meters per second)') plt.grid(True) plt.show() # Load the CSV file df = pd.read_csv(file_path) # Convert the 'Date' column to datetime format df = convert_date(df) # Set the 'Date' column as the index df = set_index(df) # Check for missing values df = check_missing(df) # Handle missing values df = handle_missing(df) # Resample the data to calculate monthly averages monthly_avg = resample_data(df) # Plot the monthly averages plot_data(monthly_avg) Download CSV File ...

June 2, 2024 · 4 min · Yogesh Sharma Neupane

Learn Basic Chinese - 12

Chinese Language Tutorial - Part 12 时不我待 (Shí bù wǒ dài) Time waits for no one. Dialogue: A: 现在几点? (Xiànzài jǐ diǎn?) B: 现在十二点一刻。 (Xiànzài shí’èr diǎn yí kè.) New Words: Pinyin Character English Translation wèn 问 to ask Xiǎomíng 小明 name of person huídá 回答 to answer Examples: 有问题吗? (Yǒu wèntí ma?) - Do you have any questions? 办公楼在教学楼北边 (Bàngōng lóu zài jiàoxué lóu běibian) - The teaching building is next to the Administrative building. Directions: ...

January 23, 2024 · 5 min · Yogesh Sharma Neupane

Headworks Design Day 1

Mr. Bharat Raj Pandey is a senior engineer at Hydro Consult Engineering Limited. Today, he shared valuable lessons in our hydropower engineering class, focusing on hydro headworks design. The initial step involves a topographical survey, requiring a D card from the survey department of Nepal to obtain XYZ coordinates. Control points are established through surveying techniques like triangulation to create a detailed map at a 1:1000 scale. The importance of a detailed map lies in understanding the depth and width needed for foundation work during hydropower headworks construction. Cross-section work, at least 500 meters upstream and downstream, at 20m intervals and 20 meters from the high flood level, is essential for design. Additionally, L-section of the river for about 1 km upstream and downstream of the headworks is crucial. ...

January 14, 2024 · 8 min · Yogesh Sharma Neupane

Learn Basic Chinese - 11

Chinese Language Tutorial: Part 11 Vocabulary New Words xiànzài (n.) - now diǎn (mw.) - o’clock kè (mw.) - quarter bàn (num.) - half zǎofàn (n.) - breakfast shíhòu (n.) - time shàngkè (v.) - to attend class Revision cóng… dào… - from… to… shàngwǔ - morning jīntiān - today yuè - month hào (rì) - date xīngqī - week xīngqīrì - Sunday Phrases tīng xiě - dictation ba - suggestion or confirmation zánmen - we; us a - tail of spoken particle chūfā - depart; to set out xíng - OK; capable jiànmiàn - to meet chà - to be less than Dialogue Asking About Time Xiǎoyè: Xiànzài jǐ diǎn? Zhíměi: Xiànzài qī diǎn yī kè. Xiǎoyè: Nǐ jǐ diǎn chī zǎofàn? Zhíměi: Wǒ qī diǎn bàn chī zǎofàn. Xiǎoyè: Nǐ shénme shíhòu shàngkè? Zhíměi: Wǒ cóng shàngwǔ bā diǎn dào shí’èr diǎn shàngkè. ...

January 13, 2024 · 3 min · Yogesh Sharma Neupane

Learn Basic Chinese - 10

Chinese Language Tutorial - Part 10: Vocabulary Pinyin Character Meaning fùqīn 父亲 father gōngzuò 工作 to work; work, job yīshēng 医生 doctor mǔqīn 母亲 mother gōngsī 公司 company zhíyuán 职员 staff member jìzhě 记者 journalist fùmǔ 父母 parents jīnnián 今年 this year duō 多 to what extent (Question) niánjì 年纪 age suì 岁 year (of age) mìmì 秘密 secret; confidential háizi 孩子 child érzi 儿子 son zhēn 真 really, very shòuhuòyuán 售货员 shop assistant jīnglǐ 经理 manager sījī 司机 driver yéye 爷爷 grandfather nǎinai 奶奶 grandmother dàngāo 蛋糕 cake míngpiàn 名片 name card jìtā 记它 to remember xǐhuan 喜欢 to like ài 爱 to love dà gē 大哥 elder brother (respectful) dà jiě 大姐 elder sister (respectful) Asking about Profession (Be careful!!) … zuò shénme gōngzuò? ...

January 13, 2024 · 6 min · Yogesh Sharma Neupane

Learn Basic Chinese - 9

Chinese Language Tutorial - Part 9: Dialogue 1: Text: Sūn lǎoshī: Nǐ xuéxí shénme? Luó shān: Wǒ xuéxí hànyǔ. Sūn lǎoshī: Nǐ zài nǎr xuéxí hànyǔ? Luó shān: Wǒ zài zhōngguó wénhuà zhōngxīn xuéxí hànyǔ. Sūn lǎoshī: Nǐmen bān yǒu duōshao xuéshēng? Luó shān: Wǒmen bān yǒu sānshí gè xuéshēng. Sūn lǎoshī: Jǐ wèi lǎoshī jiào nǐmen? Luó shān: Sān wèi lǎoshī jiāo wǒmen. Dialogue 1: Teacher: What are you studying? Luó shān: I am studying Chinese. Teacher: Where are you studying Chinese? Luó shān: I am studying Chinese at the Chinese Culture Center. Teacher: How many students are there in your class? Luó shān: We have thirty students. Teacher: How many teachers are teaching you? Luó shān: Three teachers are teaching us. ...

January 7, 2024 · 5 min · Yogesh Sharma Neupane

Learn Basic Chinese - 8

Chinese Language Tutorial - Part 8 Nǐ shì nǎ guó rén? Which country are you from? New words: Pronunciation Meaning nǎ pron. which guó n. country jiào v. to call míngzi n. name guìxìng n. asking surname (politely) guì adj. expensive; honorable xìng v./n. to surname; surname jǐ wèi lǎoshī jiāo nǐmen? How many teachers teach you? New words: Pronunciation Meaning jǐ how many wèi for respected person jiāo v. to teach zhù v. to live fáng jiān n. room diànhuà n. telephone hàomǎ n. number měi tiān xiàwǔ zuò yǒu shíhòu xiūxí chángcháng. Every day in the afternoon, sometimes, I often rest. New words: ...

January 7, 2024 · 2 min · Yogesh Sharma Neupane

Learn Basic Chinese - 7

Chinese Language Tutorial - Part 7 Health and Study Conversation Dialogue: Zhōngguó péngyǒu: Zuìjìn nǐ shēntǐ hǎo ma? (How is your health?) Lì lì: Wǒ shēntǐ hěn hǎo. (My health is very good.) Zhōngguó péngyǒu: Nǐ xuéxí máng ma? (Are you busy with studies?) Lì lì: Wǒ xuéxí bǐjiào máng. (I am relatively busy with studies.) Zhōngguó péngyǒu: Nǐ chéngjì hǎo ma? (How are your grades?) Lì lì: Mǎmahūhū. (So-so.) Zhōngguó péngyǒu: Nǐmen bān tóngxué xuéxí nǔlì ma? (Are your classmates studying hard?) Lì lì: Tāmen xuéxí fēicháng nǔlì. (They are studying very hard.) New Words tài adv. very; too tài … le bú tài dà. bú tài hǎo. lǐ n. in 里 jiàoshì li … bàngōngshì li … cèsuǒ li … yǒu v. to have; there be 有 Wǒ yǒu sān zhī bǐ. Gēge yǒu liǎng gè shǒujī. Mǎyún yǒu hěnduō qián. méi (yǒu) v./adv. not to have; have not 没有 Wǒmen bān méiyǒu zhōng guó rén. Tāmen shítáng méiyǒu bāozi. Shūbāo lǐ méiyǒu yīngyǔ shū. kōngtiáo n. air-conditioner 空调 Wǒmen jiàoshì yǒu kōngtiáo. Zhège kōngtiáo tài dàle. Nǐmen sùshè yǒu kōngtiáo ma? tóng wū n. roommate 同屋 Tā shì wǒ de tóngwū. Nà shì wǒ tóngwū de dìdi. Tāmen búshì tóngwū, tāmen shì tóngxué. lí v. from 离 Jiādémǎndū lí bó kǎlā yuǎn ma? Hóumiào lí wǒjiā bù yuǎn. Wǒ péngyou jiā lí zhèr hěn jìn. New Words Meaning tài adv. very; too lǐ n. in yǒu v. to have; there be méi (yǒu) v./adv. not to have; have not kōngtiáo n. air-conditioner tóng wū n. roommate lí v. from xuéxiào n. School duō adj. many; much tǐng adv. quite zěnmeyàng pron. what about… búcuò adj. not bad shēntǐ n. health; body shēntǐ hǎo healthy zhù wish chōuyān Smoking bǐjiào adv. quite; relatively; comparatively chéngjì n. score mǎmahūhū adj. so-so nǔlì adj. hard fēicháng adv. very Dialogue: ...

January 7, 2024 · 4 min · Yogesh Sharma Neupane

Learn Basic Chinese - 6

Chinese Language Tutorial - Part 6 Word Order in a Chinese Sentence A Chinese sentence typically follows the subject-predicate structure, where the subject, often a noun or pronoun, precedes the predicate, typically a verb or adjective. For example: Sub + Predicate: tā shì lǎoshī. pǔruì shi liúxuéshēng. tā hěn piàoliang. Sentence Making Use the given words to create sentences: zhè bǐ shì ____________ (This pen is ____________.) shū xīn hěn ____________ (The book is _____________.) zhōngguórén tā shì ____________ (Chinese, he/she is ___________.) The Attributive and Structural Particle “的” When indicating possession, the particle “的” is inserted between the attributive and the qualified object. For example: ...

January 6, 2024 · 3 min · Yogesh Sharma Neupane

Learn Basic Chinese - 5

Chinese Language Tutorial - Part 5 New Words Verbs qù (去) - to go rènshi (认识) - to meet; to know xuéxí (学习) - to learn; to study Adjectives gāoxìng (高兴) - happy Pronouns zhè (这) - this nà (那) - that Particles de (的) - of yíxiàr (一下) - casual action (once) Nouns hànyǔ (汉语) - Chinese Language bān (班) - class kǒuyǔ (口语) - Spoken Language xuésheng (学生) - student Níbó’ěr (尼泊尔) - Nepal rén (人) - people zhè (这) - this nà (那) - that péngyou (朋友) - friend Jiādémǎndū (加德满都) - Kathmandu Bókǎlā (博卡拉) - Pokhara Lán pí ní (兰比尼) - Lumbini Proper Nouns Pǔruì (普瑞) - Pradeep Luóshān (罗山) - Roshan Lìlì (丽丽) - Sonali Additional Words hé (和) - and; with jiàoshì (教室) - classroom dà (大) - big xīn (新) - new tóngxué (同学) - classmate hòu (厚) - thick piàoliang (漂亮) - pretty; beautiful jíle (极了) - extremely nǚ’ér (女儿) - daughter cōngming (聪明) - clever kě’ài (可爱) - lovely kàn (看) - to look shuài (帅) - handsome xiǎo (小) - small, little Conversation A: Qǐngwèn, túshūguǎn zài nǎr? B: Jiù zài nàr. A: Qǐngwèn, shūdiàn zài nǎr? B: Duìbuqǐ, wǒ bù zhīdào. ...

January 6, 2024 · 3 min · Yogesh Sharma Neupane

Learn Basic Chinese - 4

Chinese Language Tutorial - Part 4 New Words Vocabulary yào (要) - would like to; want to huàn (换) - to change qián (钱) - money duōshao (多少) - how much, how many bǎi (百) - hundred měiyuán (美元) - US dollar lúbǐ (卢比) - Rupees Measure Words bēi (杯) - cup, glass kuài (yuán) (块/元) - Chinese monetary unit gè (个) - a general measure word máo (jiǎo) (毛/角) - 1/10 of yuan fēn (分) - 1/10 of jiao píng (瓶) - bottle běn (本) - a measure word for books, etc. Numbers èr liǎng (二两) - two two èr bēi kāfēi (二杯咖啡) - two cups of coffee (incorrect) liǎng bēi kāfēi (两杯咖啡) - two cups of coffee (correct) Conversation A: 两杯咖啡多少钱? (Liǎng bēi kāfēi duōshao qián?) B: 五十块。 ...

January 6, 2024 · 2 min · Yogesh Sharma Neupane

Learn Basic Chinese - 3

Chinese Language Tutorial - Part 3 Food and Drinks Vocabulary chī (吃) - to eat shénme (什么) - what jiǎozi (饺子) - dumpling mǐfàn (米饭) - cooked rice miàntiáo (面条) - noodle miànbāo (面包) - bread bāozi (包子) - steamed stuffed bun Conversation A: 你吃什么? (Nǐ chī shénme?) B: 我吃饺子。 (Wǒ chī jiǎozi.) Drinks Vocabulary hē (喝) - to drink píjiǔ (啤酒) - beer chá (茶) - tea kāfēi (咖啡) - coffee shuǐ (水) - water niúnǎi (牛奶) - milk Kěkǒu-kělè (可口可乐) - Coca-cola Conversation A: 你喝什么? (Nǐ hē shénme?) B: 我喝咖啡。 (Wǒ hē kāfēi.) ...

January 6, 2024 · 2 min · Yogesh Sharma Neupane