[Python] Loading csv files using pandas

About Pandas

Pandas is a Python data analysis library. Installation is `` `pip install pandas```

Read csv file

sample.py


import pandas as pd
xxx = pd.read_csv('sample.csv') #xxx is an appropriate variable

print (xxx) #Output of all columns

sample

スクリーンショット 2017-08-09 16.36.54.png sample.csv

If you want to output the student number with the highest score in sample.csv

sample2.py


import pandas as pd
filename = pd.read_csv('sample.csv',encoding="SHIFT-JIS")#Or UTF-8

listA = []
listB = []

listA =  filename['student number']
listB =  filename['Score']
max=0
leng = len(listA)

for n in range(leng):
	if listB[n]>max:
		max=listB[n]
		num = n
print ('The student number with the highest score is'+str(listA[num]))

Summary

Pandas is convenient because you can easily read Excel files such as csv. If you want to analyze data using python from now on, why not use it?

Recommended Posts

[Python] Loading csv files using pandas
[Python] Reading CSV files
Read csv with python pandas
Data analysis using python pandas
Process csv data with python (count processing using pandas)
Transpose CSV files in Python Part 1
Analyze JMeter jtl files using pandas
Handle Excel CSV files with Python
Python hand play (RDKit descriptor calculation: SDF to CSV using Pandas)
[AWS] Using ini files with Lambda [Python]
[Python] Accelerates loading of time series CSV
[Easy Python] Reading Excel files with pandas
I analyzed cowrie (honeypot) using python pandas
Download files in any format using Python
How to read CSV files in Pandas
My pandas (python)
Start using Python
Csv in python
Scraping using Python
python pandas notes
Read Python csv data with Pandas ⇒ Graph with Matplotlib
Python pandas: Search for DataFrame using regular expressions
I want to visualize csv files using Vega-Lite!
Reading and writing CSV and JSON files in Python
Character encoding when using csv module of python 2.7.3
I tried reading a CSV file using Python
Operate Redmine using Python Redmine
Fibonacci sequence using Python
Cross tabulation using Pandas
Data analysis using Python 0
Collectively register data in Firestore using csv file in Python
Read CSV file: pandas
Data cleaning using Python
Installing pandas on python2.6
Using Python #external packages
How to convert JSON file to CSV file with Python Pandas
WiringPi-SPI communication using Python
[Introduction for beginners] Reading and writing Python CSV files
[Python] Summary of table creation method using DataFrame (pandas)
Age calculation using python
Make a CSV formatting tool with Python Pandas PyInstaller
[Python] A memo to write CSV vertically with Pandas
Copy S3 files from Python to GCS using GSUtil
Search Twitter using Python
Csv tinkering with python
Get files from Linux using paramiko and scp [Python]
Name identification using python
Python --Tagging MP3 files
Notes using Python subprocesses
Read Python csv file
Try using Tweepy [Python2.7]
Combine multiple Excel files loaded using pandas into one
Python application: Pandas # 3: Dataframe
Remove headings from multiple format CSV files with python
Python Basic --Pandas, Numpy-
[Python] Open the csv file in the folder specified by pandas
Convert from Pandas DataFrame to System.Data.DataTable using Python for .NET
Recursively copy files from the directory directly under the directory using Python
Try to operate an Excel file using Python (Pandas / XlsxWriter) ①
Try to operate an Excel file using Python (Pandas / XlsxWriter) ②
[R] [Python] Memo to read multiple csv files in multiple zip files