Professional Documents
Culture Documents
Extract
Extract
Extract
import os
# Path to the flight_data folder where all .csv files are NOTE: '/' not '\'
path = 'C:/Users/LEFE/Downloads/flight_data'
filenames = []
# For each file, we want to extract 2 columns for example, 'lon_rad' and 'lat_rad'
# We create an empty database 'output' where each row corresponds to a file name
and the columns are 'lon_rad' and 'lat_rad'
output = pd.DataFrame(data=None, index=filenames, columns=['lon_rad', 'lat_rad',
'wow'])
# Iterate over all file names inside path folder (stored in list filenames)
for file in filenames:
# Read file, extract 'lon_rad', 'lat_rad', convert to numpy array
database = pd.read_csv('{}/{}.csv'.format(path, file))[['lon_rad', 'lat_rad',
'wow']].to_numpy()
# Store the array into the output database
if database[0, -1] == 0:
continue
else:
output.loc[file, :] = database[0, :]
output = output.dropna()
# Save all into a Output.csv file
output.to_csv('Output.csv', header=True, encoding='utf-8')