lhl
首页
python
leetcode
产品思想
软件测试
博客 (opens new window)
github (opens new window)
首页
python
leetcode
产品思想
软件测试
博客 (opens new window)
github (opens new window)
  • python

    • Python 基础

    • Python 数据库

      • Python&Mysql
      • Pandas
        • Pandas
    • 面向对象

    • Python Web

    • Python 进阶

  • leetcode

  • 软件测试

  • Git

  • linux

  • 产品

  • MySql

  • docker

  • python
  • 数据库
2023-07-22
目录

Pandas

# Pandas

# 简单使用

import pandas as pd

pd.set_option('display.max_columns', None)
df = pd.read_excel('nba.xlsx')
print(df.to_string())
print('--------------------------')
print('输出一列或多列')
print(df['Name'])   ## 输出单列
print(df[['Name', 'Team', 'Position']])     ## 输出多列
print('--------------------------')
print('输出一行或多行')
print(df.iloc[0])   ## 第一行
print(df.iloc[[0]])   ## 第一行
print(df.iloc[[0,1,2]])     ## 多行
print('type df.iloc[0]: ', type(df.iloc[0]))
print('type df.iloc[[0,1]]: ', type(df.iloc[[0,1]]) )
print('--------------------------')
print('输出一格或一个区域')
print(df['Name'][0])       ## 一格
print(df[['Name', 'Team', 'Number']][0:16]) ## 一个区域

# pandas 遍历

import pandas as pd

pd.set_option('display.max_columns', None)

df = pd.read_excel('nba.xlsx')

for i in df.index:
    for j in df.iloc[[i]]:
        print(df[j][i])

# 数据筛选

import pandas as pd

pd.set_option('display.max_columns', None)

df = pd.read_excel('nba.xlsx')

## 数据进行筛选
## Salary > 1500000
players = df[ df['Salary'] > 1500000 ]
print(players)
Python&Mysql
面向对象基础

← Python&Mysql 面向对象基础→

最近更新
01
lhl learn notes
02
filter
06-09
03
decorator
06-09
更多文章>
Theme by Vdoing
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式