How to apply the same string constants to a multiple float values using python?

klemm77

I have a series of values in one file and I want to add two "descriptors" to all the series of values using python script.

Example:

Values:

1 2 3  
1 3 4

Descriptors:

Ford truck

End result:

1 2 3 Ford truck  
1 3 4 Ford truck

I would appreciate any help. I have looked at hstack, but am unsure this is the best approach.

zimmerrol

Assuming that the name of the raw file is fname and the name of the output file should be outputFile you could do this:

with open(fname) as inputFile:
    content = inputFile.readlines()
    content = [x.strip() + "Ford truck" for x in content]

    with open(ofname, "w") as outputFile:
        for item in content:
            outputFile.write("%s\n" % item) 

This code will read all lines of your raw input file, removes all trailing white space, adds Ford truck to each line and saves the result on the output file.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to extract multiple float values from a string in Python

How to extract multiple values from the same String with Regex in Python?

How to apply multiple functions to same column in Python?

How to loop through multiple values in the same string?

How to apply multiple column filter(String) in python

How to replace a string using a dictionary containing multiple values for a key in python

How to access numeric constants using the Float trait?

Using subprocess in python with multiple values and same argument

Apply Same Aggregation on Multiple Columns when Using Groupby (python)

How to extract the values after Comparison Operators in string using regex and find if value is object/ str or int/float in python?

How to accept the integer and float values in same input variable in python?

How to add using HashMap multiple values(different types, an int and a string) with the same key?

Extract Float Values from String in Python (and possibly using Regex)

How do you apply the same action to multiple variables efficiently in Python?

How to apply a custom function to the same dataframe multiple times in python?

how to apply filter on field using multiple values in mongoose

Apply the same maths equation to multiple jQuery values

Multiple constants in same class

Multiple lambda outputs in string replacement using apply [Python]

How to parse float values from string using REGEX in java

How to apply multiple custom functions to the same column without using apply every time?

How to label x&y values using string and numbers at the same time in a graph on Python

Sum multiple values for same key in lists using python

Scrapping data with multiple values with same class using python Beautifulsoup

How to dynamically apply variables to the values of a dictionary using Python and/or RobotFramework

How to pretty print using jq, so that multiple values are on the same line?

how to enter values in multiple tables using same id

How to multiple update lines using values from the same register?

How to get values from string using Python