Pandas学习-Day3

pandas 基础

Pandas 可以从各种文件格式比如 CSV、JSON、SQL、Microsoft Excel 导入数据;

可以对各种数据进行运算操作,比如归并、再成形、选择,还有数据清洗和数据加工特征

数据结构是 Series(类似于一维数组的对象);DataFrame(表格型数据)

import pandas 
pandas.__version__  #查看版本
'1.0.5'
  1. Pandas Series 【类似表格中的一个列,可以保存任何类型的数据】由索引(index)和列组成

pd.Series(data,index,dtype,name,copy)

参数说明:

data:一组数据(ndarray 类型)。

index:数据索引标签,如果不指定,默认从 0 开始。

dtype:数据类型,默认会自己判断。

name:设置名称。

copy:拷贝数据,默认为 False。

import pandas as pd
import pandas as pd

a = ["Google", "Runoob", "Wiki"]

b = pd.Series(a, index = ["x", "y", "z"])
print(b)      
print(b["y"])  #根据索引值读取数据
x    Google
y    Runoob
z      Wiki
dtype: object
Runoob

可以根据字典创建Series

import pandas as pd

sites = {1: "Google", 2: "Runoob", 3: "Wiki"}

myvar = pd.Series(sites, index = [1, 2], name="RUNOOB-Series-TEST" )  #name="RUNOOB-Series-TEST" 设置series名称参数

print(myvar)
1    Google
2    Runoob
Name: RUNOOB-Series-TEST, dtype: object
  1. Pandas DataFrame 【每列都可以是不同的值类型(数值/字符串/布尔型),有行索引也有列索引】

pd.DataFrame( data, index, columns, dtype, copy)

参数说明:

data:一组数据(ndarray、series, map, lists, dict 等类型)。

index:索引值,或者可以称为行标签。

columns:列标签,默认为 RangeIndex (0, 1, 2, …, n) 。

dtype:数据类型。

copy:拷贝数据,默认为 False。

Pandas DataFrame 是一个二维的数组结构,类似二维数组。

import pandas as pd
data1 = [['张三',100],['李四',90],['王五',88]]     #使用列表创建
data2 = {'姓名':['张三','李四','王五'],'成绩':['90','87','65']}   #使用ndarrays创建
data3 = [{'张三':55,'李四':66,'王五':77},{'张三':'C','李四':'B','王五':'A'}]    #使用字典创建,key为列名
df1 = pd.DataFrame(data1,columns=['姓名','成绩'])                 #columns列名,需要加[]
df2 = pd.DataFrame(data2)
df3 = pd.DataFrame(data3,index=["成绩",'等级'])                   #设置索引值,行标签
print(df1)
print(df2)
print(df3)

   姓名   成绩
0  张三  100
1  李四   90
2  王五   88
   姓名  成绩
0  张三  90
1  李四  87
2  王五  65
    张三  李四  王五
成绩  55  66  77
等级   C   B   A
  1. Pandas CSV文件

import pandas as pd

df = pd.read_csv(‘文件名.csv’) #pd.read_csv() 读取CSV文件

print(df.to_string()) #to_string()函数:使数据全部输出不省略
df.to_csv(‘文件名.csv’) #将dataframe存储为csv文件
数据处理
head(n) #读取前面n行
print(df.head()) #默认返回五行tail(n) #读取尾部n行,超过尾部行数,空行字段值返回NaN
print(df.tail(n))info() #返回表格的基本信息
print(df.info())
4. Pandas Json文件

import pandas as pd
import json           #别忘了导入json模块
from pandas.io.json import json_normalize
data = pd.read_json('./Desktop/test_json_data.json')   #读取json文件
with open('./Desktop/test_json_data.json','r')as f:     #用json模块载入数据
    data = json.loads(f.read())
df = pd.DataFrame(data)
#print(df.to_string())
df       ####这里print(df)输出会丢失数据框格式
idisActivebalanceageusernameemailphoneregisteredlatitudelongitudetagsgreetingfavoriteFruit
00True1,957.8823Altaaltamckee@zensus.com+1 (898) 593-34702020-06-05T08:12:50 -08:0055.067808-126.171323[proident, ipsum, elit, esse, pariatur, labore...Hello, undefined! You have 6 unread messages.banana
11True1,591.2040Lilianlilianmckee@zensus.com+1 (872) 565-32042022-01-26T09:50:15 -08:005.555640-14.003746[id, cillum, elit, ad, est, velit, tempor]Hello, undefined! You have 9 unread messages.apple
22False2,538.8030Frankfrankmckee@zensus.com+1 (849) 506-33652016-09-18T11:05:30 -08:002.818690128.647055[excepteur, ullamco, reprehenderit, irure, cul...Hello, undefined! You have 1 unread messages.apple
33NaN3,561.5422Paulapaulamckee@zensus.com+1 (978) 462-28842020-10-24T02:07:08 -08:0074.538512101.372685[adipisicing, incididunt, minim, culpa, incidi...Hello, undefined! You have 9 unread messages.apple
44True1,141.4440Lauralauramckee@zensus.com+1 (970) 430-36912014-05-31T09:28:16 -08:0064.7659946.237858[nulla, officia, enim, ullamco, do, dolor, mol...Hello, undefined! You have 9 unread messages.strawberry
..........................................
7171True3,683.6035Beasleybeasleymckee@zensus.com+1 (827) 494-39772015-02-10T03:59:44 -08:00-73.593769143.929530[anim, laboris, quis, labore, duis, magna, sit]Hello, undefined! You have 5 unread messages.banana
7272False3,375.8333Robertarobertamckee@zensus.com+1 (810) 577-37542016-03-17T05:24:50 -08:00-23.12039458.612489[ut, eiusmod, consequat, laborum, aliquip, qui...Hello, undefined! You have 6 unread messages.strawberry
7373False3,045.6932Freemanfreemanmckee@zensus.com+1 (823) 503-37452019-08-12T05:46:30 -08:00-80.556985-104.552454[consequat, deserunt, do, in, pariatur, est, o...Hello, undefined! You have 10 unread messages.strawberry
7474False1,717.9820Catalinacatalinamckee@zensus.com+1 (942) 443-29962015-04-16T10:18:41 -08:00-20.941469-17.722748[et, sit, consectetur, laborum, deserunt, magn...Hello, undefined! You have 3 unread messages.strawberry
7575False1,274.4733Irwinirwinmckee@zensus.com+1 (946) 521-33132019-09-07T12:48:45 -08:00-47.913944-40.715072[esse, aliquip, sit, ex, occaecat, Lorem, cons...Hello, undefined! You have 1 unread messages.strawberry

76 rows × 13 columns

复杂的json文件,考虑读取内嵌字段,将数据完整解析

data1 = pd.json_normalize(data,record_path = ['tags'])  # pd.json_normalize()展平数据,使用参数record_path=[]对json文件有内嵌的数据完整的解析出来
print(data1)
             0
0     proident
1        ipsum
2         elit
3         esse
4     pariatur
..         ...
538        sit
539         ex
540   occaecat
541      Lorem
542  consequat

[543 rows x 1 columns]

数据清洗【数据缺失、数据格式错误、错误数据或重复数据】

(1)数据缺失处理

print(df['isActive'].isnull())    #isnull() 判断各个单元格是否为空。  为True表明该单元格有缺失是空的
0     False
1     False
2     False
3      True
4     False
      ...  
71    False
72    False
73    False
74    False
75    False
Name: isActive, Length: 76, dtype: bool

删除包含空字段的行,可以使用 dropna() 方法

DataFrame.dropna(axis=0, how=‘any’, thresh=None, subset=None, inplace=False)

参数说明:

axis:默认为 0,表示逢空值剔除整行,如果设置参数 axis=1 表示逢空值去掉整列。

how:默认为 ‘any’ 如果一行(或一列)里任何一个数据有出现 NA 就去掉整行,如果设置 how=‘all’ 一行(或列)都是 NA 才去掉这整行。

thresh:设置需要多少非空值的数据才可以保留下来的。

subset:设置想要检查的列。如果是多个列,可以使用列名的 list 作为参数。

inplace:如果设置 True,将计算得到的值直接覆盖之前的值并返回 None,修改的是源数据
df.dropna(subset=[‘isActive’], inplace = True) #移除指定列有空值的行
还可以指定空数据类型

nulltype = ["n/a", "na", "--"]
df = pd.read_json('./Desktop/test_json_data.json', nulltype)
print(df['isActive'].isnull())
0     False
1     False
2     False
3      True
4     False
      ...  
71    False
72    False
73    False
74    False
75    False
Name: isActive, Length: 76, dtype: bool

fillna() 方法来替换一些空字段
df.fillna(12345, inplace = True) #修改源数据 DataFrame, 可以使用 inplace = True 参数

格式错误处理

df['registered'] = pd.to_datetime(df['registered'])  # 格式化日期 to_datetime()        
print(df.to_string())
    id isActive   balance age    username                       email              phone                 registered   latitude   longitude                                                                  tags                                        greeting favoriteFruit
0    0     True  1,957.88  23        Alta        altamckee@zensus.com  +1 (898) 593-3470  2020-06-05 08:12:50-08:00  55.067808 -126.171323                 [proident, ipsum, elit, esse, pariatur, labore, nisi]   Hello, undefined! You have 6 unread messages.        banana
1    1     True  1,591.20  40      Lilian      lilianmckee@zensus.com  +1 (872) 565-3204  2022-01-26 09:50:15-08:00   5.555640  -14.003746                            [id, cillum, elit, ad, est, velit, tempor]   Hello, undefined! You have 9 unread messages.         apple
2    2    False  2,538.80  30       Frank       frankmckee@zensus.com  +1 (849) 506-3365  2016-09-18 11:05:30-08:00   2.818690  128.647055  [excepteur, ullamco, reprehenderit, irure, culpa, occaecat, ullamco]   Hello, undefined! You have 1 unread messages.         apple
3    3      NaN  3,561.54  22       Paula       paulamckee@zensus.com  +1 (978) 462-2884  2020-10-24 02:07:08-08:00  74.538512  101.372685          [adipisicing, incididunt, minim, culpa, incididunt, sit, ad]   Hello, undefined! You have 9 unread messages.         apple
4    4     True  1,141.44  40       Laura       lauramckee@zensus.com  +1 (970) 430-3691  2014-05-31 09:28:16-08:00  64.765994    6.237858                    [nulla, officia, enim, ullamco, do, dolor, mollit]   Hello, undefined! You have 9 unread messages.    strawberry
5    5    False  3,475.50  35       Boyer       boyermckee@zensus.com  +1 (806) 520-2707  2019-03-14 03:36:01-08:00  64.697295  -10.047144        [excepteur, elit, et, mollit, nostrud, consequat, adipisicing]   Hello, undefined! You have 5 unread messages.        banana
6    6     True  1,724.26  28         Gay         gaymckee@zensus.com  +1 (821) 505-3033  2015-04-24 03:46:47-08:00 -74.777288  104.977168                     [labore, laboris, tempor, velit, est, qui, ipsum]   Hello, undefined! You have 8 unread messages.         apple
7    7     True  3,134.76  39     Marlene     marlenemckee@zensus.com  +1 (951) 563-3448  2019-03-02 12:09:10-08:00  54.001815   81.353144            [do, nostrud, cupidatat, aliquip, pariatur, sint, aliquip]   Hello, undefined! You have 8 unread messages.        banana
8    8     True  3,907.32  20       Mayra       mayramckee@zensus.com  +1 (850) 470-2965  2014-06-15 07:04:58-08:00 -72.784577  -86.005952                          [dolor, et, esse, velit, sit, irure, aliqua]   Hello, undefined! You have 7 unread messages.    strawberry
9    9    False  2,347.74  40      Horton      hortonmckee@zensus.com  +1 (831) 459-2644  2020-11-18 03:29:09-08:00   2.928268  -13.225237               [pariatur, consectetur, et, ullamco, qui, Lorem, minim]   Hello, undefined! You have 1 unread messages.         apple
10  10     True  2,365.19  39       Aisha       aishamckee@zensus.com  +1 (817) 597-2863  2020-04-29 01:55:41-08:00 -45.308095  149.528702                     [quis, deserunt, ad, est, eiusmod, voluptate, eu]   Hello, undefined! You have 9 unread messages.         apple
11  11    False  1,215.03  36      Butler      butlermckee@zensus.com  +1 (888) 448-2583  2021-02-09 02:58:52-08:00 -88.059546  -18.318412                         [laborum, nisi, et, aliquip, ea, nostrud, eu]  Hello, undefined! You have 10 unread messages.        banana
12  12     True  3,388.41  22    Julianne    juliannemckee@zensus.com  +1 (866) 575-2771  2019-07-19 03:12:55-08:00 -11.362040  124.727470                       [qui, duis, ad, elit, occaecat, culpa, aliquip]   Hello, undefined! You have 8 unread messages.        banana
13  13     True  2,590.43  22      Lucile      lucilemckee@zensus.com  +1 (806) 428-2761  2021-07-20 10:19:07-08:00 -73.754497 -107.050303                      [magna, mollit, cillum, id, aute, excepteur, et]   Hello, undefined! You have 3 unread messages.        banana
14  14    False  3,029.17  33       Cross       crossmckee@zensus.com  +1 (835) 561-3823  2014-07-26 03:19:57-08:00  80.212593   20.497338                  [sint, Lorem, sit, id, elit, consequat, adipisicing]   Hello, undefined! You have 4 unread messages.        banana
15  15    False  3,465.10  26       Hayes       hayesmckee@zensus.com  +1 (858) 418-2994  2021-09-21 06:13:59-08:00  35.584980  166.962556              [quis, eu, aliqua, incididunt, culpa, incididunt, ipsum]   Hello, undefined! You have 7 unread messages.    strawberry
16  16    False  2,866.15  28   Valentine   valentinemckee@zensus.com  +1 (972) 597-3027  2014-01-03 01:55:15-08:00 -33.369981  169.125766            [nulla, officia, laborum, officia, fugiat, elit, deserunt]   Hello, undefined! You have 7 unread messages.        banana
17  17    False  3,465.57  26       Weiss       weissmckee@zensus.com  +1 (805) 451-3175  2020-08-21 06:34:59-08:00 -46.299543  -28.604967              [voluptate, Lorem, quis, ullamco, pariatur, anim, nulla]   Hello, undefined! You have 5 unread messages.    strawberry
18  18     True  1,504.14  21   Gwendolyn   gwendolynmckee@zensus.com  +1 (923) 489-2289  2021-11-10 12:11:48-08:00 -12.737915 -102.107850                [ullamco, tempor, Lorem, velit, aliqua, ad, consequat]  Hello, undefined! You have 10 unread messages.        banana
19  19    False  2,386.82  24       Effie       effiemckee@zensus.com  +1 (878) 588-2853  2018-08-29 02:24:18-08:00  70.833282 -151.771232                [sit, proident, anim, culpa, aliqua, consequat, Lorem]   Hello, undefined! You have 4 unread messages.         apple
20  20     True  3,886.90  23       Adams       adamsmckee@zensus.com  +1 (994) 485-2227  2020-11-30 04:01:02-08:00  44.005370 -124.988102                     [veniam, ipsum, labore, duis, eiusmod, do, magna]  Hello, undefined! You have 10 unread messages.    strawberry
21  21     True  2,238.56  23        Rice        ricemckee@zensus.com  +1 (903) 555-3429  2015-02-24 12:45:15-08:00  34.662514 -143.133505            [adipisicing, duis, elit, aute, sit, voluptate, consequat]   Hello, undefined! You have 3 unread messages.         apple
22  22    False  1,291.01  23      Bonner      bonnermckee@zensus.com  +1 (988) 493-2700  2014-06-01 07:52:21-08:00  70.957043 -176.544590              [ad, velit, ad, non, exercitation, laboris, consectetur]   Hello, undefined! You have 3 unread messages.        banana
23  23    False  1,632.91  31        Lisa        lisamckee@zensus.com  +1 (986) 412-2109  2017-06-17 06:39:12-08:00 -67.744103   70.840212                  [Lorem, laborum, labore, ea, quis, non, adipisicing]   Hello, undefined! You have 6 unread messages.         apple
24  24    False  1,865.56  24         Rae         raemckee@zensus.com  +1 (812) 463-2528        2016-02-14 00:00:00 -33.410055   99.174982                  [amet, nostrud, qui, tempor, eiusmod, aliqua, irure]   Hello, undefined! You have 4 unread messages.        banana
25  25     True  2,601.47  32      Graham      grahammckee@zensus.com  +1 (931) 492-2595  2020-05-09 01:03:45-08:00 -72.266549  -66.621125               [amet, officia, Lorem, culpa, culpa, reprehenderit, et]   Hello, undefined! You have 9 unread messages.        banana
26  26     True  2,636.52  24         Pat         patmckee@zensus.com  +1 (931) 402-3655  2022-02-15 05:13:02-08:00  35.061864 -147.882429                          [quis, minim, aute, commodo, sint, sint, id]   Hello, undefined! You have 3 unread messages.    strawberry
27  27     True  3,151.01  28        Teri        terimckee@zensus.com  +1 (877) 472-3965  2015-12-30 10:39:53-08:00 -75.313044  -35.944372                   [eu, reprehenderit, ad, ex, excepteur, nulla, amet]   Hello, undefined! You have 7 unread messages.         apple
28  28    False  1,434.27  37     Alvarez     alvarezmckee@zensus.com  +1 (956) 553-2543  2016-09-07 11:36:01-08:00  -7.298283   16.037206            [velit, eu, consectetur, laborum, proident, minim, mollit]   Hello, undefined! You have 8 unread messages.    strawberry
29  29     True  1,448.50  36      Glenda      glendamckee@zensus.com  +1 (845) 571-2665  2014-01-21 11:53:44-08:00  65.268129 -171.211242                    [ad, cupidatat, labore, tempor, id, anim, ullamco]   Hello, undefined! You have 3 unread messages.    strawberry
30  30     True  3,806.19  33    Anderson    andersonmckee@zensus.com  +1 (931) 562-3707  2015-07-10 10:40:28-08:00 -61.587878  158.539182                 [sit, minim, qui, consectetur, enim, duis, consequat]  Hello, undefined! You have 10 unread messages.         apple
31  31     True  3,460.04  30     Abigail     abigailmckee@zensus.com  +1 (984) 496-3669  2020-08-25 01:52:26-08:00  87.002621  -38.911094                     [amet, pariatur, proident, cillum, in, duis, qui]   Hello, undefined! You have 6 unread messages.    strawberry
32  32    False  3,720.77  31        Ruiz        ruizmckee@zensus.com  +1 (848) 469-2279  2015-10-24 06:17:33-08:00 -58.896833    7.025146  [ullamco, occaecat, nisi, adipisicing, veniam, reprehenderit, irure]   Hello, undefined! You have 4 unread messages.    strawberry
33  33     True  3,014.05  29     Collier     colliermckee@zensus.com  +1 (875) 557-3031  2020-08-27 12:18:45-08:00  64.591316  -87.169913              [sit, nulla, sint, id, duis, reprehenderit, adipisicing]   Hello, undefined! You have 1 unread messages.        banana
34  34     True  2,028.29  38       Sadie       sadiemckee@zensus.com  +1 (910) 554-2893  2019-03-18 05:00:57-08:00 -24.263531   14.855673                       [officia, cillum, est, duis, velit, quis, enim]   Hello, undefined! You have 8 unread messages.         apple
35  35     True  1,561.30  20     Chapman     chapmanmckee@zensus.com  +1 (908) 414-2543  2020-10-16 03:10:41-08:00   8.034721 -145.131804              [dolor, anim, proident, tempor, consequat, ipsum, velit]   Hello, undefined! You have 5 unread messages.         apple
36  36     True  3,536.22  27    Galloway    gallowaymckee@zensus.com  +1 (970) 446-2556  2015-10-18 04:18:11-08:00 -66.944486 -143.806012        [quis, proident, reprehenderit, veniam, anim, voluptate, enim]   Hello, undefined! You have 2 unread messages.         apple
37  37     True  2,080.36  28      Dianna      diannamckee@zensus.com  +1 (983) 400-2468  2016-03-18 10:45:04-08:00 -83.729513 -110.771729                [anim, ea, nostrud, dolor, magna, consectetur, tempor]   Hello, undefined! You have 9 unread messages.    strawberry
38  38    False  1,484.28  25       Elsie       elsiemckee@zensus.com  +1 (870) 515-3100  2018-04-24 05:09:23-08:00  48.739835   96.256471              [dolore, magna, irure, quis, consequat, eu, adipisicing]   Hello, undefined! You have 5 unread messages.        banana
39  39     True  2,272.51  27       Grace       gracemckee@zensus.com  +1 (847) 448-2234  2017-04-25 03:11:43-08:00  28.372655  -17.323308                   [culpa, elit, magna, elit, nostrud, tempor, dolore]   Hello, undefined! You have 8 unread messages.         apple
40  40    False  3,128.01  27       Scott       scottmckee@zensus.com  +1 (954) 569-2317  2016-11-25 06:56:54-08:00  23.128915   98.232304            [commodo, non, consectetur, laboris, cupidatat, Lorem, do]   Hello, undefined! You have 6 unread messages.         apple
41  41     True  3,720.90  38       Melba       melbamckee@zensus.com  +1 (830) 404-3765  2016-10-30 02:19:12-08:00  84.728934  120.650407            [laborum, aliqua, minim, cillum, aliqua, enim, incididunt]   Hello, undefined! You have 1 unread messages.         apple
42  42    False  3,041.59  37       Berta       bertamckee@zensus.com  +1 (995) 548-2412  2015-05-15 04:39:48-08:00  76.510890  -36.770177                    [deserunt, minim, qui, aliquip, quis, eu, eiusmod]   Hello, undefined! You have 8 unread messages.        banana
43  43     True  2,008.12  24       Anita       anitamckee@zensus.com  +1 (821) 488-2329  2022-02-16 09:33:46-08:00  61.611504  -43.435384                    [nulla, ut, enim, amet, adipisicing, veniam, amet]  Hello, undefined! You have 10 unread messages.         apple
44  44    False  1,404.88  30      Louisa      louisamckee@zensus.com  +1 (943) 516-2188  2016-08-10 11:20:23-08:00 -70.276405   58.914492                    [irure, nostrud, velit, enim, labore, id, ullamco]   Hello, undefined! You have 5 unread messages.    strawberry
45  45    False  1,503.90  37       Marie       mariemckee@zensus.com  +1 (973) 568-3017  2019-08-19 08:05:57-08:00  71.916984 -158.612553                    [aliquip, cupidatat, sit, amet, nisi, nulla, elit]   Hello, undefined! You have 8 unread messages.           NaN
46  46    False  2,347.77  38     Janelle     janellemckee@zensus.com  +1 (940) 501-3123  2017-04-19 12:45:18-08:00 -71.843323  141.156843           [Lorem, reprehenderit, mollit, pariatur, in, dolore, culpa]   Hello, undefined! You have 3 unread messages.    strawberry
47  47    False  3,982.52  36       Cheri       cherimckee@zensus.com  +1 (877) 402-2657  2021-11-16 09:03:57-08:00 -12.500234 -136.904004                       [Lorem, velit, cillum, ex, anim, pariatur, non]   Hello, undefined! You have 2 unread messages.    strawberry
48  48     True  1,892.86  40        Bush        bushmckee@zensus.com  +1 (855) 444-2550  2017-05-03 10:21:37-08:00  -2.348724  119.208400                            [non, tempor, ipsum, eu, amet, aute, enim]   Hello, undefined! You have 6 unread messages.         apple
49  49     True  3,300.77  28       Burch       burchmckee@zensus.com  +1 (937) 511-3492  2021-01-30 11:41:31-08:00 -48.961518  -15.346772                  [excepteur, proident, ipsum, esse, do, sit, commodo]   Hello, undefined! You have 6 unread messages.         apple
50  50    False  1,368.95  26      Booker      bookermckee@zensus.com  +1 (987) 587-2545  2015-05-20 01:31:32-08:00  61.984045 -125.380179                       [laboris, esse, minim, et, magna, ex, proident]   Hello, undefined! You have 9 unread messages.        banana
51  51    False  1,901.40  36        Faye        fayemckee@zensus.com  +1 (946) 600-2847  2016-02-03 01:15:43-08:00 -28.080360   -7.373616                [nostrud, excepteur, laborum, elit, sint, id, commodo]   Hello, undefined! You have 4 unread messages.    strawberry
52  52    False  1,665.98  40     Johnnie     johnniemckee@zensus.com  +1 (856) 591-3673  2021-05-19 05:08:44-08:00 -30.056231  -19.230976                [dolore, duis, minim, irure, exercitation, sint, sunt]   Hello, undefined! You have 3 unread messages.    strawberry
53  53     True  1,474.40  31       April       aprilmckee@zensus.com  +1 (845) 409-2098  2021-03-22 07:35:53-08:00  -5.786634   56.888648                             [dolore, culpa, deserunt, in, ea, id, ut]   Hello, undefined! You have 1 unread messages.         apple
54  54     True  3,300.08  35    Kathleen    kathleenmckee@zensus.com  +1 (871) 562-3959  2021-12-12 05:47:47-08:00 -34.926525  102.345966                            [incididunt, sit, ea, qui, dolor, do, qui]   Hello, undefined! You have 4 unread messages.         apple
55  55     True  3,503.40  21     Hammond     hammondmckee@zensus.com  +1 (982) 589-3035  2021-07-29 07:32:51-08:00  72.984266   35.085423                [in, sit, nostrud, culpa, et, exercitation, cupidatat]  Hello, undefined! You have 10 unread messages.        banana
56  56    False  2,149.11  26      Chavez      chavezmckee@zensus.com  +1 (933) 418-2082  2014-05-13 07:38:35-08:00  74.535419 -124.452737       [amet, officia, velit, tempor, sunt, exercitation, adipisicing]   Hello, undefined! You have 5 unread messages.    strawberry
57  57     True  1,181.71  36     Carlson     carlsonmckee@zensus.com  +1 (828) 407-3719  2015-10-29 04:23:45-08:00 -32.909352  177.408092              [laborum, dolore, excepteur, culpa, labore, ullamco, do]   Hello, undefined! You have 2 unread messages.         apple
58  58    False  2,467.18  22      Morgan      morganmckee@zensus.com  +1 (839) 513-2398  2020-09-01 08:25:27-08:00  27.835247  -30.500342                                                    dolore,fugiat,anim  Hello, undefined! You have 10 unread messages.        banana
59  59    False  2,692.63  36       Lynda       lyndamckee@zensus.com  +1 (974) 484-3374  2018-09-24 01:15:56-08:00  -4.651066  -88.589914         [adipisicing, duis, dolore, velit, commodo, tempor, pariatur]   Hello, undefined! You have 3 unread messages.    strawberry
60  60     True  3,681.55  37    Maryanne    maryannemckee@zensus.com  +1 (957) 568-3099  2017-05-21 04:14:46-08:00  46.012669 -159.558260         [officia, laborum, in, incididunt, minim, adipisicing, minim]   Hello, undefined! You have 3 unread messages.         apple
61  61     True  2,925.17  23  Richardson  richardsonmckee@zensus.com  +1 (934) 507-2009  2015-12-11 09:08:36-08:00 -76.771339 -156.898958  [reprehenderit, consectetur, aliquip, consectetur, officia, non, id]   Hello, undefined! You have 8 unread messages.         apple
62  62     True  1,661.74  30       Ronda       rondamckee@zensus.com  +1 (854) 499-2748  2019-02-23 08:42:11-08:00 -17.063641  -38.553417        [officia, irure, mollit, adipisicing, irure, dolor, cupidatat]   Hello, undefined! You have 2 unread messages.        banana
63  63     True  2,595.95  29    Michelle    michellemckee@zensus.com  +1 (815) 576-3766  2019-11-09 08:32:18-08:00  14.176912  164.448364                             [esse, non, non, sint, do, amet, laboris]   Hello, undefined! You have 4 unread messages.    strawberry
64  64    False  3,491.92  38     Dolores     doloresmckee@zensus.com  +1 (906) 543-2133  2022-01-25 05:16:21-08:00  -6.811998  151.352407                  [Lorem, culpa, est, deserunt, labore, voluptate, ea]   Hello, undefined! You have 5 unread messages.         apple
65  65     True  3,609.82  32    Christie    christiemckee@zensus.com  +1 (858) 435-2179  2016-12-24 06:53:56-08:00 -61.337755 -161.172187               [nostrud, incididunt, eu, fugiat, esse, magna, nostrud]   Hello, undefined! You have 2 unread messages.        banana
66  66     True  1,983.97  31     Lindsay     lindsaymckee@zensus.com  +1 (972) 461-3979  2015-02-25 03:26:51-08:00 -31.182554  -46.158730              [dolore, cillum, elit, occaecat, sint, Lorem, voluptate]   Hello, undefined! You have 6 unread messages.    strawberry
67  67    False  2,872.96  33      Olivia      oliviamckee@zensus.com  +1 (977) 485-3523  2019-05-20 05:28:01-08:00  37.013480  -20.686415                         [ullamco, qui, nostrud, et, cillum, esse, et]   Hello, undefined! You have 4 unread messages.        banana
68  68    False  2,644.99  20      Hudson      hudsonmckee@zensus.com  +1 (977) 525-3646  2014-09-17 06:12:40-08:00 -76.698465  -53.394675             [pariatur, esse, qui, ullamco, fugiat, officia, pariatur]   Hello, undefined! You have 3 unread messages.        banana
69  69    False  3,132.67  31      Dotson      dotsonmckee@zensus.com  +1 (995) 431-3943  2017-03-13 09:42:54-08:00  79.578958 -113.181480                    [et, consectetur, occaecat, anim, esse, ea, ipsum]   Hello, undefined! You have 5 unread messages.         apple
70  70     true  3,125.21  21       Floyd       floydmckee@zensus.com  +1 (849) 430-3468  2021-06-01 12:55:05-08:00 -34.919145  174.163382                     [amet, consectetur, velit, et, dolor, dolor, est]   Hello, undefined! You have 7 unread messages.    strawberry
71  71     True  3,683.60  35     Beasley     beasleymckee@zensus.com  +1 (827) 494-3977  2015-02-10 03:59:44-08:00 -73.593769  143.929530                       [anim, laboris, quis, labore, duis, magna, sit]   Hello, undefined! You have 5 unread messages.        banana
72  72    False  3,375.83  33     Roberta     robertamckee@zensus.com  +1 (810) 577-3754  2016-03-17 05:24:50-08:00 -23.120394   58.612489                [ut, eiusmod, consequat, laborum, aliquip, quis, amet]   Hello, undefined! You have 6 unread messages.    strawberry
73  73    False  3,045.69  32     Freeman     freemanmckee@zensus.com  +1 (823) 503-3745  2019-08-12 05:46:30-08:00 -80.556985 -104.552454                 [consequat, deserunt, do, in, pariatur, est, officia]  Hello, undefined! You have 10 unread messages.    strawberry
74  74    False  1,717.98  20    Catalina    catalinamckee@zensus.com  +1 (942) 443-2996  2015-04-16 10:18:41-08:00 -20.941469  -17.722748                [et, sit, consectetur, laborum, deserunt, magna, amet]   Hello, undefined! You have 3 unread messages.    strawberry
75  75    False  1,274.47  33       Irwin       irwinmckee@zensus.com  +1 (946) 521-3313  2019-09-07 12:48:45-08:00 -47.913944  -40.715072                  [esse, aliquip, sit, ex, occaecat, Lorem, consequat]   Hello, undefined! You have 1 unread messages.    strawberry
df
idisActivebalanceageusernameemailphoneregisteredlatitudelongitudetagsgreetingfavoriteFruit
00True1,957.8823Altaaltamckee@zensus.com+1 (898) 593-34702020-06-05 08:12:50-08:0055.067808-126.171323[proident, ipsum, elit, esse, pariatur, labore...Hello, undefined! You have 6 unread messages.banana
11True1,591.2040Lilianlilianmckee@zensus.com+1 (872) 565-32042022-01-26 09:50:15-08:005.555640-14.003746[id, cillum, elit, ad, est, velit, tempor]Hello, undefined! You have 9 unread messages.apple
22False2,538.8030Frankfrankmckee@zensus.com+1 (849) 506-33652016-09-18 11:05:30-08:002.818690128.647055[excepteur, ullamco, reprehenderit, irure, cul...Hello, undefined! You have 1 unread messages.apple
33NaN3,561.5422Paulapaulamckee@zensus.com+1 (978) 462-28842020-10-24 02:07:08-08:0074.538512101.372685[adipisicing, incididunt, minim, culpa, incidi...Hello, undefined! You have 9 unread messages.apple
44True1,141.4440Lauralauramckee@zensus.com+1 (970) 430-36912014-05-31 09:28:16-08:0064.7659946.237858[nulla, officia, enim, ullamco, do, dolor, mol...Hello, undefined! You have 9 unread messages.strawberry
..........................................
7171True3,683.6035Beasleybeasleymckee@zensus.com+1 (827) 494-39772015-02-10 03:59:44-08:00-73.593769143.929530[anim, laboris, quis, labore, duis, magna, sit]Hello, undefined! You have 5 unread messages.banana
7272False3,375.8333Robertarobertamckee@zensus.com+1 (810) 577-37542016-03-17 05:24:50-08:00-23.12039458.612489[ut, eiusmod, consequat, laborum, aliquip, qui...Hello, undefined! You have 6 unread messages.strawberry
7373False3,045.6932Freemanfreemanmckee@zensus.com+1 (823) 503-37452019-08-12 05:46:30-08:00-80.556985-104.552454[consequat, deserunt, do, in, pariatur, est, o...Hello, undefined! You have 10 unread messages.strawberry
7474False1,717.9820Catalinacatalinamckee@zensus.com+1 (942) 443-29962015-04-16 10:18:41-08:00-20.941469-17.722748[et, sit, consectetur, laborum, deserunt, magn...Hello, undefined! You have 3 unread messages.strawberry
7575False1,274.4733Irwinirwinmckee@zensus.com+1 (946) 521-33132019-09-07 12:48:45-08:00-47.913944-40.715072[esse, aliquip, sit, ex, occaecat, Lorem, cons...Hello, undefined! You have 1 unread messages.strawberry

76 rows × 13 columns

重复数据处理
要清洗重复数据,可以使用 duplicated() 和 drop_duplicates() 方法。

print(df.duplicated()) #如果对应的数据是重复的,duplicated() 会返回 True,否则返回 False。

df.drop_duplicates(inplace=True) # 删除重复数据,可以直接使用


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

酸菜鱼的精神世界

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值