4
#df

index  a   b   c
1      2   3   4
2      3   4   5

Please help me how to extract columns "a" and "c" with all the rows but without the index column.

df[["a","c"]] # But index no. is also coming, so how to remove the index no.?

Goutam
  • 307
  • 2
  • 9

1 Answers1

4

DataFrames and Series will always have an index, you can use:

df[["a","c"]].values

output:

array([[2, 4],
       [3, 5]], dtype=int64)
kederrac
  • 15,339
  • 4
  • 25
  • 45
  • I wnat to export the file in csv, my code is: df[["b","c"]].to_csv("C:\\Desktop\\File.csv") ; but still unable remove the Index column. – Goutam Apr 17 '20 at 14:52
  • this is correct. But it is not completely solved my issue. Let me know if you have any solution for this. – Goutam Apr 17 '20 at 14:57
  • @Goutam to save to a CSV you can use:`numpy.savetxt("foo.csv", a, delimiter=",")` where `a = df[["a","c"]].values` – kederrac Apr 17 '20 at 14:59
  • you can have a look over https://stackoverflow.com/questions/6081008/dump-a-numpy-array-into-a-csv-file – kederrac Apr 17 '20 at 14:59