Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

import pandas as pd

import os

# Path to the flight_data folder where all .csv files are NOTE: '/' not '\'
path = 'C:/Users/LEFE/Downloads/flight_data'
filenames = []

# Store all names of files inside path in a list called filenames


for file in os.listdir(path):
if file.endswith(".csv"):
filenames.append(file.split('.')[0])

# 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[-2, -1] == 0:
continue
else:
output.loc[file, :] = database[-2, :]
output = output.dropna()
# Save all into a Output.csv file
output.to_csv('Output.csv', header=True, encoding='utf-8')

You might also like