-2

What is the syntax of reading file ,writing file in python.and How to read csv file and excel file in DataFrames(pandas).

Mayank Porwal
  • 31,737
  • 7
  • 30
  • 50
amigana _34
  • 15
  • 1
  • 1
  • 6
  • 4
    Possible duplicate of [Reading an Excel file in python using pandas](https://stackoverflow.com/questions/17063458/reading-an-excel-file-in-python-using-pandas) – snipsnipsnip Nov 06 '18 at 09:36

4 Answers4

2
   df = pd.read_csv('myfile.csv')
   df = pd.read_excel('myfile.xlsx')
Mayank Porwal
  • 31,737
  • 7
  • 30
  • 50
1

To read:

df = pd.read_excel('filename.xlsx')
df = pd.read_csv('filename.csv')

To write:

df.to_csv('filename.csv')
df.to_excel('filename.xlsx')

if you just googled "pandas read excel"..

dejanmarich
  • 1,163
  • 7
  • 21
1

See pandas.read_excel() for Excel and pandas.read_csv() for CSV files.

iz_
  • 14,740
  • 2
  • 25
  • 40
0
import pandas as pd
df=pd.read_csv('file_name.csv')

this will result into Dataframe.If you want to read a specific column and want output as series.

df=pd.read_csv('file_name.csv',usecols=['col_name'],squeeze=True)
Abhinav Vajpeyi
  • 106
  • 1
  • 5