0

I already imported the csv files into python. The problem with append is when I plot it, the second file did not start from the top but continues from the last point of the first file. Here, let me show you the code and the figure.

import os
import pandas as pd
import matplotlib.pyplot as plt

### Set your path to the folder containing the .csv files
PATH = "D:\\TUGAS\\TA\\TUYS\\Data TA dari Garuda\\Format CSV\\Hard Landing\\Format 1"

### Fetch all files in path
fileNames = os.listdir(PATH)

### Filter file name list for files ending with .csv
#fileNames = [file for file in fileNames if '.csv' in file]
TES = pd.Series([])
X = pd.Series([])

### Loop over all files
for file in fileNames:

### Read .csv file and append to list
    df = pd.read_csv( file, skiprows=[0,1,3,4])
    df.columns = [column.replace(" ","_") for column in df.columns]
    df.columns = [column.replace("/","_") for column in df.columns]
    X = X.append(df)

TES = TES.append(X)
### Create line for every file
plt.plot(TES.DISTANCE_TO_THRESHOLD, TES.ALTITUDE_ABOVE_FIELD_ELEV)
plt.ylabel("Altitude (ft)")
plt.xlabel("Distance from threshold (nm)")
plt.xlim(5,-2)
plt.ylim(-50,1000)
### Generate the plot
plt.show()

The figure :

enter image description here

and the figure supposed to look like this (in reverse)

enter image description here

Any ideas how to correct it?

1 Answer 1

0

Using append creates a single series of all the files (lines) you want to plot. Therefore, they are joined together into a single line. See pandas documentation on append.

Instead of creating X as a Series you could create X as a list and loop thru the list to plot on the same figure. Something like this

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.