Reputation: 4470
Scenario:
Using pandas to read a csv. Problem is all the columns and the data is present in a single column in the csv file.
CSV format (A is a column in the CSV):
A
"c1 c2"
"19 91"
Code Tried:
data = pd.read_csv("/test.csv")
print (data.head())
Op:
c1\c2\c3\c4\c5\c6\c7\
19910710\t111\t22...
Required Op:
c1 c2 c3
000 222 333
The format of the csv is all the columns and values are present in a single column "A" separated by "SPACE". Since there is a "SPACE" separating, the values are getting prefixed with "t". Is there any shortcut to get the required output.
Any suggestions are helpful
Upvotes: 1
Views: 65
Reputation: 4470
Solution:
data = pd.read_csv("test.csv", delim_whitespace=True)
Upvotes: 1
Reputation: 26
If each column is being separated by a \, you might want to do, data = pd.read_csv("/test.csv", sep='\')
then since you wanted to select those three specifically I would do,
data = pd.read_csv("/test.csv")
my_data = data['c1', 'c2', 'c3']
print (my_data)
Upvotes: 1