• Convert String List to Integer List in Python
    27 April

    Convert 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 […]

  • Convert Object to Float in Pandas
    25 April

    Convert 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 […]

  • PowerShell check if String contains List
    25 April

    PowerShell Check if List Contains String

    Using -Contains Operator Use the -Contains operator to check if the list contains the specified string in PowerShell. $list = @("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday") $searchString = "Wednesday" $list -Contains $searchString True In the above example, we used an array operator represented with @() to create a list, which we stored in the […]

  • PowerShell Split and get last value
    24 April

    PowerShell Split and Get Last Value

    Using Split() Method Use the Split() method with the indexing operator to split the specified string and get the last value in PowerShell. $string = "This is a sample string" $lastElement = ($string.Split(" "))[-1] Write-Host "The last element of '$string' is '$lastElement'" The last element of 'This is a sample string' is 'string' First, we […]

  • Convert XLSX to CSV in PowerShell
    23 April

    Convert XLSX to CSV in PowerShell

    The xlsx file can be easily converted into csv using the following methods: Before converting a file, please ensure that your PowerShell is opened in the administrative mode, and the execution policy should not be set to Restricted. Get-ExecutionPolicy Set-ExecutionPolicy Restricted In the above code, we used the Get-ExecutionPolicy command to check if the execution […]

  • Convert CSV to XLSX in PowerShell
    23 April

    Convert CSV to XLSX in PowerShell

    The csv file can be easily converted into xlsx using the following methods: [toc] Before converting files, please verify that your PowerShell is opened in administrative mode and that the execution policy is not set to Restricted. Get-ExecutionPolicy Set-ExecutionPolicy Restricted The above output demonstrates that the execution policy is set to Restricted. So, if the […]

  • Run String as Command in PowerShell
    22 April

    Run String as Command in PowerShell

    Using Invoke-Expression Cmdlet Use the Invoke-Expression cmdlet to run a string as a command in PowerShell. Invoke-Expression cmdlet evaluates string as command and return the result of string expression. Here is simple exampple: $command = "notepad.exe" Invoke-Expression $command This will open new notepad window. Here is more complicated example. $command = "Get-Process | Sort-Object -Property […]

  • Run Curl Command in PowerShell
    22 April

    Run Curl Command in PowerShell

    In PowerShell 3.0 and higher, we have Invoke-WebRequest and Invoke-RestMethod cmdlets; curl is an alias of the Invoke-WebRequest in PowerShell. Most learners make it confused with the Invoke-RestMethod cmdlet. In PowerShell 7 and higher, the Invoke-RestMethod cmdlet is the default cmdlet for sending RESTful web service requests. It is another built-in cmdlet in PowerShell mainly […]

  • PowerShell check if String starts with
    22 April

    PowerShell Check if String Starts with

    Using StartsWith() Method Use the StartsWith() to check if string starts with another string in PowerShell. $text = "Hello, world!" $prefix = "Hello" $startsWithPrefix = $text.StartsWith($prefix) Write-Host "Text: $text" Write-Host "Prefix: $prefix" Write-Host "Does '$text' start with '$prefix'? $startsWithPrefix" Text: Hello, world! Prefix: Hello Does 'Hello, world!' start with 'Hello'? True In the above code, […]

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.