Reputation: 87
I'm a new user to pandas. I run the following code with my titanic csv file (which I got from a tutorial) and the command titanic.sex returns the sex row as expected.
titanic = pd.read_csv('/Users/eflannery/Dropbox/titanic.csv')
titanic.Sex
0 male
1 female
2 female
3 female
4 male
5 male
6 male
7 male
8 female
9 female
10 female
11 female
12 male
13 male
14 female
...
876 male
877 male
878 male
879 female
880 female
881 male
882 female
883 male
884 male
885 female
886 male
887 female
888 female
889 male
890 male
Name: Sex, Length: 891, dtype: object
If I run the same code with one of my csv files, it doesn't pull out the cov column as expected. I checked that my file is a csv. Any ideas?
sam = pd.read_csv('/Users/eflannery/Dropbox/Cartika/CNV_data/samFlags_NK65EvolB20_baseCounts2.csv')
sam.cov
<bound method DataFrame.cov of chrom pos cov
0 berg02 1 0
1 berg02 2 0
2 berg02 3 0
3 berg02 4 0
4 berg02 5 2
5 berg02 6 3
6 berg02 7 3
7 berg02 8 3
8 berg02 9 4
9 berg02 10 4
10 berg02 11 4
11 berg02 12 4
12 berg02 13 4
13 berg02 14 4
14 berg02 15 4
15 berg02 16 4
16 berg02 17 5
17 berg02 18 5
18 berg02 19 5
19 berg02 20 5
20 berg02 21 5
21 berg02 22 5
22 berg02 23 5
23 berg02 24 6
24 berg02 25 6
25 berg02 26 6
26 berg02 27 6
27 berg02 28 6
28 berg02 29 6
29 berg02 30 6
... ... ... ...
18433379 PBANKA_API 30273 25
18433380 PBANKA_API 30274 25
18433381 PBANKA_API 30275 25
18433382 PBANKA_API 30276 25
18433383 PBANKA_API 30277 25
18433384 PBANKA_API 30278 24
18433385 PBANKA_API 30279 24
18433386 PBANKA_API 30280 24
18433387 PBANKA_API 30281 24
18433388 PBANKA_API 30282 24
18433389 PBANKA_API 30283 24
18433390 PBANKA_API 30284 24
18433391 PBANKA_API 30285 18
18433392 PBANKA_API 30286 16
18433393 PBANKA_API 30287 16
18433394 PBANKA_API 30288 16
18433395 PBANKA_API 30289 16
18433396 PBANKA_API 30290 13
18433397 PBANKA_API 30291 13
18433398 PBANKA_API 30292 13
18433399 PBANKA_API 30293 13
18433400 PBANKA_API 30294 10
18433401 PBANKA_API 30295 8
18433402 PBANKA_API 30296 5
18433403 PBANKA_API 30297 5
18433404 PBANKA_API 30298 5
18433405 PBANKA_API 30299 5
18433406 PBANKA_API 30300 5
18433407 PBANKA_API 30301 5
18433408 PBANKA_API 30302 2
[18433409 rows x 3 columns]>
Upvotes: 0
Views: 206
Reputation: 352989
Using the .
access syntax can be handy for convenience, but you've tripped across a problem with it: when there's a method of the same name, you get the method, not the column. Use dictionary-style access instead:
>>> df
chrom pos cov
0 berg02 1 0
1 berg02 2 0
2 berg02 3 1
>>> df.cov
<bound method DataFrame.cov of chrom pos cov
0 berg02 1 0
1 berg02 2 0
2 berg02 3 1>
>>> df["cov"]
0 0
1 0
2 1
Name: cov, dtype: int64
Or I guess you could actually compute the covariance :-)
>>> df.cov()
pos cov
pos 1.0 0.500000
cov 0.5 0.333333
Upvotes: 3