Skip to content

Programming Articles

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

Python

Pandas

How to add a new column to an existing DataFrame?

Sample query: I have the following indexed DataFrame with named columns and rows not- continuous numbers: I would like to add a new column, ‘e’, to the existing data frame and …

How to add a new column to an existing DataFrame? Learn More
Python

If Python is interpreted, what are .pyc files?

Query explained: I’ve been given to understand that Python is an interpreted language…However, when I look at my Python source code I see .pyc files, which Windows identifies as “Compiled Python Files”. Where do …

If Python is interpreted, what are .pyc files? Learn More
Python

How to print all the current properties and values of an object in Python

Query explained: So what I’m looking for here is something like PHP’s print_r function. This is so I can debug my scripts by seeing what’s the state of the object in question. …

How to print all the current properties and values of an object in Python Learn More
Pandas / Python

Get a list from Pandas DataFrame column headers

The sample query has been explained below. How to get a list from Pandas DataFrame column headers? You can get the values as a list by doing: Also, you can …

Get a list from Pandas DataFrame column headers Learn More
Python

How to create a constant in Python?

Query explained: Is there a way to declare a constant in Python? In Java we can create constant values in this manner: What is the equivalent of the above Java …

How to create a constant in Python? Learn More
Python

How to write a line to file in Python?

Query: I’m used to doing print >>f, “hi there” However, it seems that print >> is getting deprecated. What is the recommended way to do the line above? Update: Regarding all those answers …

How to write a line to file in Python? Learn More
Python

How to add new keys to a dictionary in Python?

In this post, we’ll learn how to add new keys to a dictionary in Python. How to add new keys to a dictionary in Python? You create a new key/value …

How to add new keys to a dictionary in Python? Learn More
Explanations / Python

What is the difference between __str__ and __repr__?

In this post, we’ll learn the difference between __str__ and __repr__ in Python. As answered by Ned, my rule of thumb: __repr__ is for developers, __str__ is for customers. Now, what is the difference …

What is the difference between __str__ and __repr__? Learn More
Python

Does Python have a string ‘contains’ substring method?

Query: I’m looking for a string.contains or string.indexof method in Python. I want to do: Does Python have a string ‘contains’ substring method? No, it doesn’t if you want string.contains(), but you can use …

Does Python have a string ‘contains’ substring method? Learn More
Explanations / Python

What is the difference between staticmethod and classmethod in Python?

Answer: Maybe a bit of example code will help: Notice the difference in the call signatures of foo, class_foo and static_foo: Below is the usual way an object instance calls a method. The object …

What is the difference between staticmethod and classmethod in Python? Learn More
Programming / Python

What are metaclasses in Python? [Answered]

Metaclasses in Python explained: Classes as objects Before understanding metaclasses, you need to master classes in Python. And Python has a very peculiar idea of what classes are, borrowed from …

What are metaclasses in Python? [Answered] Learn More
Python

What is the ternary conditional operator in Python?

In this post, we’ll learn how to use the ternary operator in python. Does Python have a ternary conditional operator? Yes, it was added in version 2.5. The expression syntax is: First condition is …

What is the ternary conditional operator in Python? Learn More
Python

What does if __name__ == “__main__”: do in Python? [Answered]

Query: Given the following code, what does the if __name__ == “__main__”: do? What does if __name__ == “__main__“: do? Answer #1: Short Answer It’s boilerplate code that protects users from accidentally …

What does if __name__ == “__main__”: do in Python? [Answered] Learn More
Formatted Codes / Pandas

How to create conditional columns in pandas dataframe/series? [Answered]

Sample query: I have a dataframe along the lines of the below: I want to add another column to the dataframe (or generate a series) of the same length as …

How to create conditional columns in pandas dataframe/series? [Answered] Learn More
Pandas

How to filter Pandas dataframe using ‘in’ and ‘not in’ like in SQL? [Answered]

Sample query: How can I achieve the equivalents of SQL’s IN and NOT IN? I have a list with the required values. Here’s the scenario: My current way of doing this is as …

How to filter Pandas dataframe using ‘in’ and ‘not in’ like in SQL? [Answered] Learn More
Formatted Codes / Python

How to flatten an irregular list of lists? [Answered]

Sample problem: Yes, I know this subject has been covered before, but as far as I know, all solutions, except for one, fail on a list like this: Where the …

How to flatten an irregular list of lists? [Answered] Learn More
Formatted Codes / Tkinter

Tkinter: AttributeError: NoneType object has no attribute [Answered]

Problem explained: I’ve created this simple GUI: I get the UI up and running. When I click on the Grab button, I get the following error on the console: Why is entryBox set to None? …

Tkinter: AttributeError: NoneType object has no attribute [Answered] Learn More

Posts navigation

Previous 1 2 3 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.