Python
24 JulyGet Output from Python Script in Bash
Using Substitution Syntax Use Substitution Syntax ($(...)) to get output from a Python script and store it in a Bash variable. print("Welcome to Java2Blog!") result=$(python my_script.py) echo $result Welcome to Java2Blog! We used the command substitution syntax,$(command), to capture the output of the Python script (my_script.py) in a Bash variable (result). Here, the command was […]
04 MayCount Unique Values in NumPy Array
1. Introduction One of the common tasks Numpy Users may encounter is count unique values in Numpy Array that can help in exploring the distribution of Nummy Array. In this article, we will see different ways to count unique values in Numpy Array. 2. Using np.unique() Method with len() Method Use np.unique() method with len() […]
04 MayCreate Array of Arrays in Python
Use numpy.array() Function To create an array of the arrays in Python: Use the np.array() function to create a numpy.ndarray type array of the arrays. import numpy as np array1 = np.array([1,2,3]) array2 = np.array([4,5,6]) array3 = np.array([7,8,9]) array = np.array([array1, array2, array3]) print(array) [[1 2 3] [4 5 6] [7 8 9]] The Python […]
27 AprilConvert String List to Integer List in Python
Using map() Method Use the map() method with list() method to convert string list to integer list in Python. string_list = ['5', '6', '7', '8', '9'] integer_list = list(map(int, string_list)) print(integer_list) for item in integer_list: print(type(item)) [5, 6, 7, 8, 9] <class 'int'> <class 'int'> <class 'int'> <class 'int'> <class 'int'> First, we defined a […]
25 AprilConvert Object to Float in Pandas
1. Introduction Pandas is python library for data analysis and manipulation. One of the common tasks is to convert data type of column from object to float. We can achieve this using astype() or to_numeric() methods. Method 1: Using astype() df['column_name'] = df['column_name'].astype(float) Method 2: Using to_numeric() df['column_name'] = pd.to_numeric(df['column_name']) Let’s see each method in […]
15 AprilNameError: Name requests Is Not Defined
Python has a name error when you try to use a variable or function that is not defined currently. It means that Python has no idea where to locate the requests module or library you are trying to use in your code when you receive the nameError: name 'requests' is not defined error. There are […]
15 AprilConvert Hex to String in Python
1. Introduction The representation of data in Hexadecimal is commonly used in computer programming. It is used to represent binary data in a human-readable form, as understanding the machine language (i.e., Binary) is difficult for humans. Hexadecimal notation is used in networking protocols, e.g., IPv6 and cryptography, and widely used in graphics, e.g. to represent […]
14 AprilNameError: Name xrange Is Not Defined in Python
This NameError: Name 'xrange' Is Not Defined in Python is one of the errors which can occur while using Python. Our objective is to identify the underlying cause of the error and then provide ways to resolve it. Using xrange() Method to Reproduce NameError Use the xrange() method to reproduce NameError in Python 3.x. for […]
14 AprilCall Python Script from Bash with Arguments
Python is a high-level language famous for its simplicity, flexibility, and readability. At the same time, Bash is a Unix shell and command language used primarily on Unix and Linux systems. Data analysis, machine learning, web development, and scientific computing tasks are widely performed using python language. On the contrary, the bash is used for […]
- 1
- 2
- 3
- …
- 42
- Nextkeyboard_arrow_right