Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在 for 循环中迭代地从一组 csv 文件中读取数据。csv 文件被命名为 ( 1.csv,2.csv依此类推)
1.csv
2.csv
读取数据的正常方式是
data = pd.read_csv('1.csv')
请有人建议在使用循环时如何1替换。ifor
1
i
for
我试过了data = pd.read_csv(i+'.csv'),data = pd.read_csv(i'.csv')但他们没有用。
data = pd.read_csv(i+'.csv')
data = pd.read_csv(i'.csv')
使用任一百分比格式
pd.read_csv('%d.csv' % i)
或者format
format
pd.read_csv('{0}.csv'.format(i))
做一个单独的字符串?
ifi确实是一个整数,使用:
filename = str(i) + '.csv' data=pd.read_csv(filename)
甚至:
data=pd.read_csv(str(i)+'.csv')
应该没事 :)