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
1 Like
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
Consider following code when conn is the name of established connection to MySQL database.
sql = SELECT * from Sales where zone = "central"; df = pandas.read_sql(sql, conn) df.head()What will be stored in df ?
Write a program to read details such as Item, Sales made in a DataFrame and then store this data in a CSV file.
Write a program to get following data in two DataFrames :
df 1:
Roll no Name 1 ABC 2 DEF df2:
Roll no Marks 1 Marks 2 Marks 3 1 70 80 75 2 60 65 70 Store these DataFrames as two separate tables in the same database.
You have a database on MySQL namely school having three tables in it — Student, Subject, Teacher. Write a program to store these tables in three DataFrames.