0

I have the following csv file:

Filesystem,Size,Used,Avail,Use,Mounted,on
/dev/sda3,196G,124G,63G,67,/
tmpfs,32G,144K,32G,1,/dev/shm
/dev/sda1,194M,42M,143M,23,/boot

I'm reading the file using the following code:

df = pandas.read_csv(tempFolder+"diskSpace.txt", sep=',',header=None)

I tried to print the Use column with three different approaches:

 print(df[Use])

 print(df['Use']) 

 print(df["Use"])

It fails to print the Use column

2
  • ... what error? Commented Oct 10, 2018 at 14:41
  • It looks like you have a header. Commented Oct 10, 2018 at 14:47

2 Answers 2

4

Remove header=None:

In [9]: df = pd.read_csv('data', sep=',')

In [10]: df
Out[10]: 
  Filesystem  Size  Used Avail  Use   Mounted  on
0  /dev/sda3  196G  124G   63G   67         / NaN
1      tmpfs   32G  144K   32G    1  /dev/shm NaN
2  /dev/sda1  194M   42M  143M   23     /boot NaN

In [11]: df['Use']
Out[11]: 
0    67
1     1
2    23
Name: Use, dtype: int64

With header=None, the column names are 0, 1, ..., 6:

In [7]: df = pd.read_csv('data', sep=',', header=None)

In [8]: df
Out[8]: 
            0     1     2      3    4         5    6
0  Filesystem  Size  Used  Avail  Use   Mounted   on
1   /dev/sda3  196G  124G    63G   67         /  NaN
2       tmpfs   32G  144K    32G    1  /dev/shm  NaN
3   /dev/sda1  194M   42M   143M   23     /boot  NaN
Sign up to request clarification or add additional context in comments.

Comments

0

your DataFrame's columns is 0,1,2,3,4.... if you specify header=None
try with:

df = pandas.read_csv(tempFolder+"diskSpace.txt", sep=',',header=0)

and also, it's 'Used', not 'Use'

Comments

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.