naz
naz

Reputation: 447

Data frame creation from an input file

I have a file which contain some floating values like

5.234234
6.434344
5.45435
7.243224
4.0999884

I want to create a dataframe from this file.It should look like

Activity
5.234234
6.434344
5.45435
7.243224
4.0999884

What I've tried is(its not working)

import pandas as pd
from StringIO import StringIO
data= open('Activity.txt').read()
pd.read_csv(StringIO(data),names='Activity',header=None)

Any help would be appreciated.

Upvotes: 1

Views: 88

Answers (1)

joaquin
joaquin

Reputation: 85683

You must use:

p.read_csv('Activity.txt', names=('Activity',))

Note:
1) You dont need to open your file.
2) names is 'array-like', for example, a tuple or list.
3) header is None by default when names parameter is specified (otherwise 0).

Upvotes: 2

Related Questions