Read the file:
The traditional method of reading. All read out, processed by line:
Fp=open ("./ps.txt", "R");
Alllines=fp.readlines ();
Fp.close ();
For Eachline in Alllines:
Print Eachline
The recommended read method, using a file iterator, is to read and display only one row at a time. This should be the case when reading large files:
Fp=open ("./ps.txt", "R");
For Eachline in FP:
Print Eachline
To read and write files using pandas:
Import Pandas as PD
Import NumPy as NP
Read the file and convert it into Np.array:
Traind=pd.read_csv ("Train.csv")
Trainy=np.array (Traind.iloc[:,-1])
Trainx=np.array (Traind.iloc[:,1:-1]) #drop ID and TARGET
Testd=pd.read_csv ("Test.csv")
Submitid=np.array (testd.iloc[:,0]) #ID column
Testx=np.array (testd.iloc[:,1:]) #drop ID
Write the file and convert it to PD. DataFrame:
Dataset_trainblend=np.zeros ((3, 2))
DFTRAINBLEND=PD. DataFrame (Dataset_trainblend)
Dftrainblend.to_csv ("Dftrainblend3.csv", header=["RFC", "GBC"], Index=false)
Read and Write files: reads and writes one line at a time in a large file. CSV file