[python] Read data

Here are some file reading methods that can be used with python. Since it is for when what kind of function was there, detailed explanation of each function is omitted.

open()

Specify the file and mode. The default mode is 'r' (read-only)

main.py


#When reading and displaying line by line
data = open('/path/to/data', 'r')

for line in data:
  print line

data.close()

#When reading and displaying all contents
data = open('/path/to/data', 'r')

all_data = data.read()
print all_data

data.close()

read_csv(), read_table() pandas Read_csv () for comma separated, read_table () for tab separated What you read is returned as a data frame

main.py


import pandas as pd

data_csv = pd.read_csv('/path/to/data.csv')
data_tsv = pd.read_table('/path/to/data.tsv')

loadtxt() numpy Also specify the delimiter and type (default is space delimiter and `` `float```) What you read is returned as an array

main.py


import numpy as np

data = np.loadtxt('/path/to/data', delimiter=' ', dtype = 'float')

Recommended Posts

[python] Read data
Read json data with python
Read Protocol Buffers data in Python3
Data analysis python
Read pandas data
[SQLAlchemy] Read data
Data analysis with python 2
Python Data Visualization Libraries
Data analysis using Python 0
Data cleaning using Python
[Python tutorial] Data structure
[Python] Sorting Numpy data
Read Python csv file
Data analysis with Python
[Python] Read From Stdin
Read data with python / netCDF> nc.variables [] / Check data size
Read Python csv data with Pandas ⇒ Graph with Matplotlib
Read table data in PDF file with Python
[Python] How to read data from CIFAR-10 and CIFAR-100
Sample data created with python
My python data analysis container
Handle Ambient data in Python
Read csv with python pandas
data structure python push pop
Python for Data Analysis Chapter 4
Python
Display UTM-30LX data in Python
Get Youtube data with python
Read Euler's formula in Python
Data Science Cheat Sheet (Python)
[Python] Notes on data analysis
My python data analytics environment
Read Namespace-specified XML in Python
Python application: data visualization # 2: matplotlib
Python data analysis learning notes
Read Outlook emails in Python
Python data type summary memo
[Python] Plot time series data
Python for Data Analysis Chapter 2
Image data type conversion [Python]
Data analysis using python pandas
Read Fortran output in python
python> tuple> data, address = s.recvfrom (10000)
Python for Data Analysis Chapter 3
Get Leap Motion data in Python.
[Python] How to FFT mp3 data
Python: Exclude tags from html data
Python Application: Data Cleansing Part 1: Python Notation
Data acquisition using python googlemap api
How to read e-Stat subregion data
Hit treasure data from Python Pandas
Get data from Quandl in Python
Experiment data fitting (Python) being added ...
Handle NetCDF format data in Python
Python course for data science_useful techniques
Read and use Python files from Python
Python data structures learned with chemoinformatics
[python] Read information with Redmine API
Python Pandas Data Preprocessing Personal Notes
Have python read the command output
Hashing data in R and Python