I'm a beginner.
I would like to import the csv file.
The data sets are as follows (simplified).
0000
0 12 12 12
0 123 123 123
data=pd.read_csv('○○.csv', sep='')
If you import as above,
0 NaN NaN NaN 0 NaN NaN 0 NaN NaN 0 NaN NaN 0
0NaNaN12NaN12NaN12NaN12
0 NaN123 NaN123 NaN123
Next, NaN is reflected in the number of spaces.
Is there any good way?
According to the Pandas I/O API documentation,
read_csv(filename, sep='\s+')
or
read_csv(filename,delim_whitespace=True)
It would be good if
The following options are also useful:
header=None
—No header line.skipinitialspace=True
—Ignore the leading blank characters.The following is an example of execution.For clarity, I create buffers from strings instead of reading from files.
>>import StringIO
>>import pandas as pd
>>buffer=StringIO.StringIO(""000000"
... 0 12 12 12
... 0 123 123 123
... """)
>>>data=pd.read_csv (buffer,header=None,delim_whitespace=True)
>> data
0 1 2 3
0 0 0 0 0
1 0 12 12 12
2 0 123 123 123
read_csv
(as far as I've seen, it's the API Reference for pandas 0.20.2)
© 2024 OneMinuteCode. All rights reserved.