I need to read certain csv files wich dont have a certain name it is aleatory in a folder which I define in the directory glob.glob , select two columns which I specify and print these csv one by one
This is my code:
import pandas as pd;
import numpy as np;
import glob;
import os;
all_files = glob.glob("C:/Users/Gamer/Documents/Colbun/Saturn/*.csv");
file_list = [];
for f in all_files:;
df = pd.read_csv(f,header=0,usecols=["t","f"]);
df.to_csv(file_list);
CodePudding user response:
Incorrect use of df.to_csv, the function takes in path object (implementing os.PathLike[str]). I would suggest appending the df in file_list inside the loop. Refer: df.to_csv function on how to use the save csv function.
CodePudding user response:
Reed 3(or more) csv and print 3 csv (or more)
This will save to a file not print.
file_list = []
for i,f in enumerate(all_files):
df = pd.read_csv(f,header=0,usecols=["t","f"])
df.to_csv(f'filename{n}.csv')
file_list.append(f'filename{i}.csv') #??