一开始遇到一个问题,Pycharm读取CSV读不出来,解决方案:

在文件名后面加上这个:encoding = "ISO-8859-1"

import pandas as pd错误文件名后面加encoding

df.shape df.head(前几行) df.tail(倒数几行) df.tail[:]全部

读取某列的数据df['goal'] 和 df.goal 是一样的读取列数据方法1读取列数据方法2

df[['name','state']]: 打印两列

df['goal'].describe():打印出最大值,最小值,偏差值等

df['goal'].describe()

count 3.786610e+05

mean 4.908079e+04

std 1.183391e+06

min 1.000000e-02

25% 2.000000e+03

50% 5.200000e+03

75% 1.600000e+04

max 1.000000e+08

Name: goal, dtype: float64

df[df.goal>=30000]:打印出goal 的值大于30000的所有数据

df[df.goal>=30000]

KsID ... usd_goal_real

1 1000003930 ... 30000.00

2 1000004038 ... 45000.00

5 1000014025 ... 50000.00

8 1000034518 ... 125000.00

9 100004195 ... 65000.00

13 1000056157 ... 200000.00

29 100011318 ... 50000.00

46 1000183112 ... 40000.00

50 1000201265 ... 60000.00

58 1000230071 ... 60000.00

df[df.goal==df.goal.max()]

df[df.goal==df.goal.max()]

KsID ... usd_goal_real

23469 1119122774 ... 1.000000e+08

33084 1168153740 ... 1.000000e+08

55009 1279992058 ... 1.000000e+08

72775 1370542565 ... 1.000000e+08

72990 1371612630 ... 1.000000e+08

df[['name','state']][df.goal==df.goal.max()]:当goal为最大的时候,打印对应的name和state

df[['name','state']][df.goal==df.goal.max()]

name state

23469 Help me start a fair media company, Trump Media failed

33084 Sage: Warrior Of The Fallen Gods (Movie) failed

55009 Kybernan Holographic Gaming Network failed

72775 Art Is Fabulous failed

72990 Wax Apple failed

77676 Bring back Pontiac failed

94636 Survival SandBox Game (Canceled) canceled

95513 This Land Called America failed

118402 Our future failed

这个网址提供pandas所有的操作,尽情用吧~https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.html​pandas.pydata.org

另外在console打的任何东西懂不会改变原本的数据集,除非采用inplace=True

df.set_index('day',inplace=True)

如果需要复原的话

df.set_index(inplace=True)

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐