python基本操作——读取列名、读取行索引、查找某值是否在某列、删除空行、字符串取某段字符
读取列名:
import pandas as pd import numpy as np file=pd.read_excel('路径/文件名.xlsx') names = file.columns.values.tolist() for i in range(len(names)+1): columns=names[i] print(columns)
删除空行:
file1 = file.dropna(axis=0) #如果axis=1则为删除空列
读取行索引:
fline_index = f.loc[f['列名'] == '指定的列值'].index.tolist()
查找某值是否在某列:
#把要查找的列转为列表然后查找 find_values = file.iloc[:,'指定列的位置'].values.tolist() value = x #x为要查找的值 if value not in find_values: print(str(value),'不存在') else: print(str(value),'存在')
字符串取某段字符:
#把一串字符串分割 strings='wo'、‘shige’、‘chu’、'xuezhe' strings.split('、')#括号中填分隔符
本文来自博客园,作者:会飞的大斗篷,转载请注明原文链接:https://www.cnblogs.com/sherlockids/p/14994212.html

浙公网安备 33010602011771号