Reputation: 141
I'm trying to plot from a CSV file using Spyder in Anaconda. But it seems Spyder is not reading my csv correctly.
The first few rows and columns of the data as appeared in Excel/Numbers:
[1/s] [Pa] [mPa·s] [mN·m]
1 100 124.83 1248.3 0.57307 Dy_fast
2 72.8 97.795 1343.5 0.44897 Dy_fast
3 53 76.539 1444.6 0.35139 Dy_fast
I don't know how make it look like Excel, the values in each () correspond to the header [1/s], [Pa] etc.. I hope its not confusing
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('7%PVA-PAA Viscosity Sweep.csv', encoding = 'ISO-8859-1', skiprows = 4)
print(df)
The output seems to be empty
Unnamed: 0
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
5 NaN
.. ...
153 NaN
154 NaN
155 NaN
156 NaN
157 NaN
[158 rows x 1 columns]
If I open the same file in Excel/Numbers, I get the desired data organized in tabular format.
I changed the encoding to encoding = 'ISO-8859-1
" because I had encountered an error before utf-8' codec can't decode byte 0xff in position 0: invalid start byte
I am using Spyder 3.3.3
Upvotes: 2
Views: 2136
Reputation: 14851
You may need to change the default separator which, in Comma-Separated Values (CSV) files is a comma:
pandas.read_csv('data.csv', sep='\s+')
The \s+
is a regular expression which means "white spaces".
If you are sure the separator is always a single TAB, then you can use \t
instead.
Upvotes: 1