Skip to content

Programming Articles

  • HOME
  • Python
  • JavaScript
  • C/C++
  • Java
  • Terms & Conditions and Privacy Policy
  • About US
Main Menu

Python

Python / Python HowTos

How to pad a string with zeroes to the left?

This is a very frequently asked question, how do I pad a numeric string with zeroes to the left, so that the string has a specific length? In this article, …

How to pad a string with zeroes to the left? Learn More
Pandas

How to delete a column from a Pandas DataFrame?

To delete a column in a DataFrame, I can successfully use: But why can’t I use the following? Since it is possible to access the column/Series as df.column_name, I expected this …

How to delete a column from a Pandas DataFrame? Learn More
Python / Python HowTos

How to delete an element from a dictionary?

The del statement removes an element: Note that this mutates the existing dictionary, so the contents of the dictionary changes for anybody else who has a reference to the same instance. To return …

How to delete an element from a dictionary? Learn More
Python

Why is it string.join(list) instead of list.join(string)?

It’s because any iterable can be joined (e.g, list, tuple, dict, set), but its contents and the “joiner” must be strings. For example: Using something other than strings will raise the following …

Why is it string.join(list) instead of list.join(string)? Learn More
Pandas

How to update the value of a row in a Python Dataframe?

In this article, we’ll learn how to update the value of a row in a Python Dataframe. If you want a direct answer and are not interested in the explanation …

How to update the value of a row in a Python Dataframe? Learn More
Python

How to read a file line-by-line into a list in Python?

This code will read the entire file into memory and remove all whitespace characters (newlines and spaces) from the end of each line: If you’re working with a large file, …

How to read a file line-by-line into a list in Python? Learn More
Python

How to remove a character from a string in Python?

In Python, you can use the replace() and translate() methods to remove characters you want to remove from a string and return a new modified string result. Strings, and especially user-generated input may contain …

How to remove a character from a string in Python? Learn More
Python

How to remove spaces from a string in python?

This article will introduce different methods to remove spaces in a messy Python string based on different scenarios and requirements. After reading, you can choose the most appropriate way for …

How to remove spaces from a string in python? Learn More
Python

How to get key with maximum value in dictionary in Python?

Sample query: I have a dictionary: keys are strings, values are integers. Example: I’d like to get ‘b’ as an answer, since it’s the key with a higher value. I did the following, …

How to get key with maximum value in dictionary in Python? Learn More
Python

How to display number with leading zeros in Python?

In Python 2 (and Python 3) you can do: Basically % is like printf or sprintf. For Python 3.+, the same behavior can also be achieved with format: Learn more about format and f-strings from this …

How to display number with leading zeros in Python? Learn More
Python

How to check if a variable exists in Python?

To check the existence of a local variable: To check the existence of a global variable: To check if an object has an attribute: How to check if a variable …

How to check if a variable exists in Python? Learn More
Python

How to run shell command and capture the output in Python?

In all officially maintained versions of Python, the simplest approach is to use the subprocess.check_output function: check_output runs a single program that takes only arguments as input.1 It returns the result exactly as printed …

How to run shell command and capture the output in Python? Learn More
Python

How to get the line count of a large file cheaply in Python?

Query statement: I need to get a line count of a large file (hundreds of thousands of lines) in python. What is the most efficient way both memory- and time-wise? …

How to get the line count of a large file cheaply in Python? Learn More
Python

How to read a text file into a string variable and strip newlines?

Sample query: I use the following code segment to read a file in python: Input file is: and when I print data I get As I see data is in list form. …

How to read a text file into a string variable and strip newlines? Learn More
Pandas

How to change column type in pandas?

Sample query: I want to convert a table, represented as a list of lists, into a Pandas DataFrame. As an extremely simplified example: What is the best way to convert the …

How to change column type in pandas? Learn More
Python / Python HowTos

How to move a file in Python?

Although os.rename() and shutil.move() will both rename files, the command that is closest to the Unix mv command is shutil.move(). The difference is that os.rename() doesn’t work if the source and destination are on different disks, while shutil.move() is …

How to move a file in Python? Learn More
Pandas

How to create a Pandas Dataframe by appending one row at a time?

In case you can get all data for the data frame upfront, there is a much faster approach than appending to a data frame: Create a list of dictionaries in …

How to create a Pandas Dataframe by appending one row at a time? Learn More

Posts navigation

1 2 … 4 Next

Featured Posts

From UNIX to Linux – History of Linux

21st November 202010th September 2022

Best themes for Ubuntu: Make Ubuntu Beautiful

20th October 202010th September 2022

Strings in Python

12th September 202010th September 2022

Is Python hard to learn? Top best learning resources

18th April 202010th September 2022

Recent posts

  • How to pad a string with zeroes to the left?
  • What is the difference between process and thread?
  • How to generate a random alpha-numeric string in Java?
  • How to auto-resize an image to fit a ‘div’ container?
  • How to get a Docker container’s IP address from the host?
  • How to display a JavaScript object?
Copyright © 2023 Programming Articles.
Powered by WordPress and HitMag.