You can change one or more column names of your pandas DataFrame with rename() method. Let’s see the sample below: Sample: On the Second script above, on the df.rename() method, inplace = True, to update in current DataFrame. And on the Third script, regex = True to prevent from warning below: Output:
Tag Archives: python
The total number of lock exceeds the lock table size in MySQL
Below error when using python with sqlalchemy module and MySQL MariaDB. Error: MySQL is trying to tell you that it doesn’t have enough room to store all of the row locks that it would need to execute your query. The only way to fix it for sure is to adjust innodb_buffer_pool_size and restart MySQL. By default, thisContinue reading “The total number of lock exceeds the lock table size in MySQL”
Split String Column into Multiple Columns in Pandas DataFrame
You can use split() method to split a pandas DataFrame text column into multiple columns. Syntax: Parameters: Returns: The split() method returns a list of strings. The example below will split A column into two columns X and Y by expanding DataFrame dimensionality: Example: Output:
Iterate pandas DataFrame over rows with iterrows method
Sometimes you want to iterate row by row of a pandas DataFrame, despite the performance you can use itterrows() method to “Iterate over DataFrame rows as (index, Series) pairs”. Code: The above code will print the filename, start and end date. Output:
Chunking Large CSV file with pandas
When working with a large CSV file, instead of loading the entire file in memory for reading, you can read CSV files as chunks by reading only a part of the file at a time which uses very little memory. With the pandas read_csv() method by specifying the chunksize parameter, you can divide a largeContinue reading “Chunking Large CSV file with pandas”
Python Get MAC Address to allow Application only for specific Users
The main purpose of this post is how to allow only a specific user to use your CLI tool, and in this post, we’ll use a computer MAC address that provides a unique id of your computer hardware. Actually, it’s easy to achieve this because you only need three lines of code below to readContinue reading “Python Get MAC Address to allow Application only for specific Users”
What is a Python Dictionary?
A Python dictionary consists of a collection of key-value pairs with unique keys. The advantage of using a dictionary is quick access to an element by a key without having to search through a full dataset, which means you can achieve both performance gain and write more readable code. Dictionary Syntax: You need to knowContinue reading “What is a Python Dictionary?”
Python For Loop with Index
In this post, we’ll go over a different approach on how to access an index in Python’s for-loop statements. And remember, you can use for-loop statements only at iterable-object such as a list, tuple, dictionary, set, and string. To access the index in Python’s for-loop statement in this post, you can use: manual indexing variableContinue reading “Python For Loop with Index”
Understanding Python slice notation
Python slicing is a very powerful way to access parts of your data, so it’s one aspect of the language that every Python programmer needs to know. But first, you need to know the difference between indexing and slicing: Indexing Index position works as a pointer to an item of your iterable object or dataContinue reading “Understanding Python slice notation”
Know the anatomy of the Pandas Series
Pandas Series is a one-dimensional labeled-array that capable to hold of any data type. Labels must be a hashable type. And element in the series can be accessed similarly to ndarray from numpy library (to create ndarray need to import numpy library). Elements of a series can be accessed in two ways: position or label/index.Continue reading “Know the anatomy of the Pandas Series”