2

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

8
  • 1
    This has nothing to do with Spyder, that's why I changed the title. Commented Mar 13, 2019 at 12:34
  • 1
    What would the desired output be? what kind of data do you have in that column? Commented Mar 13, 2019 at 12:38
  • 1
    You should provide, at least, the first rows of your CSV data file. Commented Mar 13, 2019 at 13:00
  • Your CSV file may be in a non-standard form that you may need to specify special options for. You will need to give an example of the CSV content you are trying to parse in order to get a useful answer here. The fact that you're only seeing one column may indicate you are not setting the correct column delimiter. Commented Mar 13, 2019 at 13:21
  • 1
    @user190144 Better add them to your question (edit the question), do not put them here as a comment. ;-) Commented Mar 13, 2019 at 14:32

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the explanation but I'm still getting error ` Unnamed: 0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN `
@user190144 It seems you added to your question "the data as appeared in Excel/Numbers". Please, add the data as it is written in the CSV file: open your 7%PVA-PAA Viscosity Sweep.csv with a text editor and copy-paste the first rows as code into your question. Otherwise it would be impossible to tell what your problem is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.