简体   繁体   English

如何在没有连接的情况下将多个csv加载到pandas中?

[英]How to load multiple csv into pandas without concatenate?

I would like to apply two separate graphs to each text file in a folder with subdirectories, however I wouldn't want them to be joined into one data frame. 我想将两个单独的图形应用于具有子目录的文件夹中的每个文本文件,但是我不希望它们被连接到一个数据框中。 I am currently only able to load one file into pandas at a time. 我目前只能一次将一个文件加载到pandas中。 If I put the root directory, I get an error that the File doesn't exist. 如果我放了根目录,我收到一个文件不存在的错误。

data = pd.read_csv(r'/Users/work/DexterStudio/DataFolder/*', sep=" ", header = None, na_values='NaN')

# organize data
data.drop(data.columns[[4]], axis=1, inplace=True)
data.columns = ["timestamp", "x", "y", "z"]

#get current axes object
frame1 = plt.gca()

#draw two graphs
plt.plot(data['timestamp'],data['x'],color='r', label='x-axis')
plt.plot(data['timestamp'],data['y'], color='b', label='y-axis')

# hide axes
frame1.axes.get_xaxis().set_visible(False)
plt.legend(loc='upper right')
plt.show()


plt.plot(data['timestamp'],data['z'],color='g', label='z-axis')
plt.legend(loc='upper right')
plt.show()

Just do two read statements into two variables and go from there: 只需将两个读取语句分成两个变量,然后从那里开始:

data1 = pd.read_csv(r'/Users/work/DexterStudio/DataFolder/file1', sep=" ", header = None, na_values='NaN')
data2 = pd.read_csv(r'/Users/work/DexterStudio/DataFolder/file2', sep=" ", header = None, na_values='NaN')

Note naming the files in the read statement and that you now have data1 and data2 注意命名read语句中的文件,并且您现在拥有data1和data2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM