Lets say you input: os.listdir(r'filepath')
and the output is: ['a.txt','b.txt','c.txt','d.txt','e.txt']
How could you put the file names, ['a', 'b', 'c', 'd', 'e']
into a pandas dataframe?
Lets say you input: os.listdir(r'filepath')
and the output is: ['a.txt','b.txt','c.txt','d.txt','e.txt']
How could you put the file names, ['a', 'b', 'c', 'd', 'e']
into a pandas dataframe?
Use list comprehension with DataFrame
contructor:
L = ['a.txt','b.txt','c.txt','d.txt','e.txt']
df = pd.DataFrame({'col':[x.split('.')[0] for x in L]})
print (df)
col
0 a
1 b
2 c
3 d
4 e
Thank you for suggestion @Joe Halliwell, main advantage is general solution, check this:
df = pd.DataFrame({'col': [os.path.splitext(x)[0] for x in L]})