Click here to Skip to main content
15,887,446 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have a code which reads one csv file (FILE1), and creates one txt file (FILE2). I would like to create a NEW output file. The NEW output file I would like to include:
the second column of .csv file(FILE1)
and the one column of the .txt file(FILE2)

How can I make it?

What I have tried:

My code is:


import math
import pandas as pd
import matplotlib as plt
import numpy as np

dfArxika = pd.read_csv('ALL.csv', usecols=[0,1,2,3,4,5,6,7,8,9,10], header=None, index_col=False)
print(dfArxika.columns)

#print(df)
A=dfArxika[0] 
B=dfArxika[1]
C=dfArxika[2] 

..........................................

with open('outputdata.txt','w') as fout:
    foreach item in A:
        fout.write(str(item) + "\n")
Posted
Updated 13-Nov-20 6:40am

1 solution

You can do it one of two ways:
1. Read each input file and create lists from the items you extract. Then write the output taking one item from each list for each output line.
2. Read each file one line at a time. for each pair of lines, extract the fields you want and write them to the output file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900