Read and Append csv files in a folder without knowing the name of the files?
<p>Is it possible to have numpy look for CSV files in a folder where the code resides and appends couple of the CSV files together?</p>

<p>My current code does something like this:</p>

<pre><code>data = np.loadtxt('csv data file.csv', delimiter=',', skiprows=1)
</code></pre>

<p>Where I have to combine the csv file together and assign it a name.
I want to be able to do the above and put the complete file into one and assign it to data for some data manipulation and plotting without knowing the files names. </p>

<p>I know I can do it in panda like this:</p>

<pre><code>path =r'C:\DRO\DCL_rawdata_files'
allFiles = glob.glob(path + "/*.csv")
frame = pd.DataFrame()
list_ = []
for file_ in allFiles:
    df = pd.read_csv(file_,index_col=None, header=0)
    list_.append(df)
frame = pd.concat(list_)
</code></pre>

<p>But I am trying to avoid any extra modules to add for simplicity. So can this be done with numpy?</p>

<p><em>"Knowing the names of the files"</em> has nothing to do with the problem.</p>

<p>In the example with <a href="/questions/tagged/pandas" class="post-tag" title="show questions tagged &#39;pandas&#39;" rel="tag">pandas</a>, the filenames are <em>known</em> after this line:</p>

<pre><code>allFiles = glob.glob(path + "/*.csv")
</code></pre>

<p>Now <code>allFiles</code> contains all filenames. Then, the loop goes through the filenames, loads each file and appends loaded data to <code>list_</code>. Exactly the same can be done with <a href="/questions/tagged/numpy" class="post-tag" title="show questions tagged &#39;numpy&#39;" rel="tag">numpy</a>.</p>

<p>The only special thing is merging of all data into one data set:</p>

<pre><code>frame = pd.concat(list_)
</code></pre>

<p>Again, numpy has a similar function: <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.concatenate.html" rel="nofollow"><code>numpy.concatenate</code></a>.</p>

<p>So, all together, with numpy:</p>

<pre><code>import numpy as np

path =r'C:\DRO\DCL_rawdata_files'
filenames = glob.glob(path + "/*.csv")
all_data = []
for filename in filenames:
    data = np.loadtxt(filename, delimiter=',', skiprows=1)
    all_data.append(data)
result = np.concatenate(all_data)
</code></pre>

python