I read data from many files and save it in a data frame. I want the column of the data frame to indicate which file the data came to. How to create a column with the same row repeating over and over without manually entering it?
Each file I read has ~ 100 data points (but not the same number every time). When I read each of them, I agree with the file frame along the axis = 0. It should look like this.
import numpy as np
import pandas as pd
numbers = np.random.randn(5)
labels = np.array(['file01','file01','file01','file01','file01'])
tf = pd.DataFrame()
tf['labels'] = labels
tf['numbers'] = numbers
In [8]: tf
Out[8]:
labels numbers
0 file01 -0.176737
1 file01 -1.243871
2 file01 0.154886
3 file01 0.236653
4 file01 -0.195053
(Yes, I know that I can make "file01" the column heading and add each along the axis = 1, but there are reasons why I do not want to do this.)
source
share