Reputation: 1238
My dataset CSV file is row-wise:
1,2,3,4
1000,2000,3000,4000
I want to read this file and get a dataframe output of two columns, 'index and value'.
Output:
index value
1 1000
2 2000
3 3000
If I want to get only the 'value' column, I should be able to retrieve them by doing df['value']
I tried going about it like this:
series = pd.read_csv('file.csv',index_col=0, header=0)
df= series.T
Frame=pd.DataFrame([df], columns = ["index","value"])
But this yields an error:
> ValueError: Shape of passed values is (1, 1), indices imply (2, 1)
Upvotes: 1
Views: 3380
Reputation: 11192
try this,
df=pd.read_csv('input.csv',header=None)
print df.T.rename(columns={0:'Index',1:'Value'})
print df['Value']
Out:
0 1000
1 2000
2 3000
3 4000
Name: Value, dtype: int64
Upvotes: 2