使用Python从一个图形中的多个CSV/Excel文件打印
我已经将csv文件导入python。append的问题是,当我打印它时,第二个文件不是从顶部开始的,而是从第一个文件的最后一点继续。这里,让我向您展示代码和图使用Python从一个图形中的多个CSV/Excel文件打印,python,excel,csv,plot,append,Python,Excel,Csv,Plot,Append,我已经将csv文件导入python。append的问题是,当我打印它时,第二个文件不是从顶部开始的,而是从第一个文件的最后一点继续。这里,让我向您展示代码和图 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\
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()
图为:
这个数字应该是这样的(相反)
您知道如何更正吗?使用append创建一系列要打印的文件(行)。 因此,它们被连接在一起形成一条直线。 请参见附加 你可以创建X作为一个列表,并在列表中循环以绘制在同一个图形上,而不是将X创建为一个系列