Informatics Practices
Write a program to read details such as Item, Sales made in a DataFrame and then store this data in a CSV file.
Python Pandas
1 Like
Answer
import pandas as pd
data = {'Item': ['Apple', 'Banana', 'Orange', 'Grapes'],
'Sales': [100, 150, 80, 120]}
df = pd.DataFrame(data)
df.to_csv('one.csv', index = False)Output
Item,Sales
Apple,100
Banana,150
Orange,80
Grapes,120
Answered By
1 Like
Related Questions
Consider following code when conn is the name of established connection to MySQL database.
Cars = {'Brand': ['Alto', 'Zen', 'City', 'Kia'], 'Price': [22000, 25000, 27000, 35000]} df = pd.DataFrame(Cars, columns= ['Brand', 'Price']) df.to_sql('CARS', conn, if_exists = 'replace', index = False)What will be the output of following query if executed on MySQL ?
SELECT * from CARS ;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 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.
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.