# 读取第一行(表头)
head_row = pd.read_csv('all_consumer_bill_detailed_local_bk.csv', encoding='gb18030', nrows=0)
print(head_row)
# 表头行转为 list
head_row_list = list(head_row)
# 读取第一列
col1 = pd.read_csv('all_consumer_bill_detailed_local_bk.csv', encoding='gb18030', usecols=[0])
print(col1)
# 读取csv,encoding方式主要是UTF-8和GBK
df = pd.read_csv('all_consumer_bill_detailed_local_bk.csv', encoding='gb18030')
# print(f"行读取结果:{df.values}")
# 找出第3行
row3 = df.iloc[2,:]
print(row3)
# 找出第2列
col2 = df.iloc[:, 1]
print(col2)
# 找出前两列,全部行
row_col = df.iloc[:, :2]
print(row_col)
# 按照列名查找某一列
tel = df['telephone']
print(tel)
# 按照列名查找某几列
tel_city = df[['telephone', 'province', 'city']]
print(tel_city)
# 单条件查询
# 找出telephone大于1800000000的行,所有列
aaa = df.loc[df['telephone'] > 18000000000]
# 找出telephone大于1800000000的行,中的hospital_name,owner这两列
bbb = df.loc[df['telephone'] > 18000000000, ['hospital_name', 'owner']]
# 多条件查询
# 找出telephone大于1800000000,并且province在四川的行,要hospital_name,owner这两列
ccc = df.loc[(df['telephone'] > 18000000000) & (df['province'] == '四川'), ['hospital_name', 'owner']]
# 存储结果文件
ccc.to_excel('ccc.xlsx')
ccc.to_csv('ccc.csv')
常用的pandas读取csv,读取表头,然后使用表头读取csv内容的方法:
# read csv
csv_file = r"摆位1000.csv"
head_row = pd.read_csv(csv_file, nrows=0)
head_row_list = list(head_row)
csv_results = pd.read_csv(csv_file, usecols=head_row_list, encoding='GBK')
row_list = csv_results.values.tolist()
result_list = []
for i, item in enumerate(row_list):
print("{}/{}行读取结果:{}".format(i, len(row_list), item))
java stream逆序遍历 java stream倒序
StreamStream流是jdk1.8对集合对象功能的增强,可以通过将集合转换为流模型,通过声明的方式对集合中的每个元素进行一系列并行或者串行的流水线操作举例:对数据进行排序取值从数据源中获取一组用户信息,查找年满18周岁以上的所有用户,然后针对用户信息按照工资值进行倒序排序,获取所有用户的id编号public class User{
private Long id;//用户编号