Python 对csv格式文件的数据处理
# Edit By Python3.6
import os,csv,pandas as pd
path = 'C:\\Users\\Desktop\\NBA'
filepath = os.chdir(path)
with open('A.csv') as csvfile:
reader = csv.reader(csvfile)
rows= [row for row in reader]
column = [row[1] for row in reader]
print(column)
print(rows)
print('...............')
data=pd.read_csv('A.csv')
print(data)
print('.......')
print(list(data.get('Name')))
print(type(data.get('Name')))
print('....................Df')
dataNanColumn=data.dropna(axis=1,how='any') # 只要出现nan,则删除该列,若all,则该列全为nan,才删除,此删除不会改变源文件数据
data.dropna()
dataNanRow=data.dropna(axis=0,how='any')
# drop all rows that have any NaN values
print('No Row nan')
print(dataNanRow)
print('No Column nan')
print(dataNanColumn)
获取某列,某行,去除NAN行,NAN列...
本文版权归作者所有,转载请注明出处http://www.cnblogs.com/iloverain/.未经作者同意必须保留此段声明,否则保留追究法律责任的权利.