KnowledgeBoat Logo
|

Informatics Practices

Write a program to read data from a CSV file where separator character is '@'. Make sure that :

  • the top row is used as data, not as column headers.
  • only 20 rows are read into DataFrame.

Python Pandas

2 Likes

Answer

Let the contents of the file bike.csv be the following:

Brand@Price
Honda@2500
Yamaha@2800
Suzuki@2100
Kawasaki@3200
Ducati@3500
BMW@4500
Harley-Davidson@5500
KTM@4000
Triumph@5300
Aprilia@4800
Indian@5700
Royal Enfield@3000
MV Agusta@4200
Moto Guzzi@4900
Victory@5600
Benelli@3900
Husqvarna@4800
Zero Motorcycles@6500
Energica@7500
Norton@5900

The program to read data from a CSV file is as follows:

import pandas as pd
d = pd.read_csv('one.csv', sep = '@', header = None, nrows = 20)
print(d)
                   0      1
0              Brand  Price
1              Honda   2500
2             Yamaha   2800
3             Suzuki   2100
4           Kawasaki   3200
5             Ducati   3500
6                BMW   4500
7    Harley-Davidson   5500
8                KTM   4000
9            Triumph   5300
10           Aprilia   4800
11            Indian   5700
12     Royal Enfield   3000
13         MV Agusta   4200
14        Moto Guzzi   4900
15           Victory   5600
16           Benelli   3900
17         Husqvarna   4800
18  Zero Motorcycles   6500
19          Energica   7500

Answered By

3 Likes


Related Questions