Pandas DataFrame groupby() and agg()

In Pandas, the groupby() and agg() methods are closely related as groupby() is used to group the data in a DataFrame based on one or more columns and then the agg() method is used to perform aggregation operations on those groups. After grouping the data using groupby(), you can use agg() to specify one orContinue reading “Pandas DataFrame groupby() and agg()”

Python Pandas Date Conversion: How to Handle #N/A, 1/0/1900, and Blank Dates in Excel

When working with dates in Excel, it’s common to encounter data inconsistencies such as #N/A, 1/0/1900, or blank values in the ‘date’ column. Converting such columns to datetime format can be challenging, and it may lead to errors or unexpected results. For example, in the code provided below, an error occurs when attempting to convertContinue reading “Python Pandas Date Conversion: How to Handle #N/A, 1/0/1900, and Blank Dates in Excel”

Office365 – Access with Client ID and Client Secret Using Python

On this article we will access the SharePoint with Client ID and Client Secret so we don’t have to worry about user and password. To download a file from SharePoint, you will be need 4 steps below: 1. Install Office365-REST-Python-Client Install Office365-REST-Python-Client using pip: For detail installation please refer to this link: GitHub – vgrem/Office365-REST-Python-Client:Continue reading “Office365 – Access with Client ID and Client Secret Using Python”

Rename Excel Sheet Name Using openpyxl in Python

Imagine you have multiple Excel files in a folder and you want to change the sheet name of all Excel files that contain “Documentation*” to just “Documentation”. As an example, let’s say you have two Excel files in a folder, and each Excel file has two sheets. One of the sheet names contains “Documentation”, andContinue reading “Rename Excel Sheet Name Using openpyxl in Python”

Python – Errno 13 Permission denied

I need some time to figure out this error, because some references that I found suggest to check the privilages to the file or folder that I want to access, but none of the suggestion worked. And then I realized that actually I want to read a file but I provided a folder. Let’s creatingContinue reading “Python – Errno 13 Permission denied”

timedelta – add days and substract days from dates

Python timedelta is a class of datetime.timedelta which usually used to perform datetime object manipulations, such as adding or substracting a certain amount of time between two dates or times. And timedelta object can be created by passing in the number of days, seconds, microseconds, milliseconds, minutes, hours, or weeks as arguments. Please see belowContinue reading “timedelta – add days and substract days from dates”

Split a String Column into Multiple Columns in Pandas DataFrame with Regex

To use the .str.split() function in pandas DataFrame, you can refer to this link: But in this article, we’ll use regex to split the sting values and change them to multiple columns. Let’s see the sample: Example: Script: Output: Summary The best part of using regex when you want to split a column into multipleContinue reading “Split a String Column into Multiple Columns in Pandas DataFrame with Regex”

VLOOKUP in Pandas DataFrame

To do VLOOKUP like in excel, python’s built-in class DataFrame has a very detailed and handy method by using map() and merge() functions to merge two different data tables. The merge() function does the same job as the join in SQL and uses the left join to emulate the VLOOKUP function like in Excel (IfContinue reading “VLOOKUP in Pandas DataFrame”

TypeError: Sequence item 1: expected str instance, float found

When using agg() and join() methods on pandas DataFrame, sometimes you will get two below errors: , and: These errors may be due to the NaN value in your columns. Let’s try to create these errors with the below script: You will find below errors: 1. Future Warning: 2. Type Error: Let’s fill NaN withContinue reading “TypeError: Sequence item 1: expected str instance, float found”

Concatenate Column Values in Pandas DataFrame

Sometimes you need to concatenate column values in your Pandas DataFrame to create a new unique column (uid = unique id), so you can do a look-up value from another DataFrame. From the below example you will have 4 original columns: MRBTS, LNBTS, LNCEL, and dlChBw, and then add a new column ‘UID’ by concatenatingContinue reading “Concatenate Column Values in Pandas DataFrame”