Pandas data processing (a)

Pandas data processing (a)

import pandas as pd

import numpy as np

# Numpy use to generate a set of data DataFrome

df=pd.DataFrame(np.arange(16).reshape(4,4))

print(df)

–out
0 1 2 3

0 0 1 2 3

1 4 5 6 7

2 8 9 10 11

3 12 13 14 15

# We see a line, we have not specified vertical no results have emerged,
# DataFrome because it is our two-dimensional columns, resulting in a vertical row index and the index
of course, we can also specify the index value #

df=pd.DataFrame(np.arange(16,32).reshape(4,4),index=[‘a’,‘b’,‘c’,‘d’],columns=[‘w’,‘x’,‘y’,‘z’])

print(df)

–out
w x y z
a 16 17 18 19
b 20 21 22 23
c 24 25 26 27
d 28 29 30 31

#DataFrome Import Dictionary

a = { 'Id': [ '001', '002', '003'], 'name': [ 'cat', 'dog', 'wolf'], 'sex': [ 'F' , 'M', 'M']}

df=pd.DataFrame(a)

print(df)

-Out
Id name Sex
0 001 kittens female
1002 male puppy
2003 male wolf

#pandas really powerful, and this is my very favorite place

# View row index

print(df.index)

–out

RangeIndex(start=0, stop=3, step=1)

# View column index

print(df.columns)

–out
Index([‘Id’, ‘name’, ‘sex’], dtype=‘object’)

# View data

print(df.values)

-Out
[[ '001' 'cat' 'woman']
[ '002' 'dog' 'M']
[ '003' 'coyotes' 'M']]

# View type

print(type(df))

–out
<class ‘pandas.core.frame.DataFrame’>

# View the list of data types

print(type(df))

–out
Id object
name object
sex object
dtype: object

# View Data Dimensions

print(df.shape)

–out
(3, 3)

Required to display data #

print(df.head(1))

-Out
Id name Sex
0 001 female kitten

# Displays the first line the countdown

print(df.tail(1))

-Out
Id name Sex
2 003 male coyotes

# Display list information

print(df.info())

–out

<class ‘pandas.core.frame.DataFrame’>
RangeIndex: 3 entries, 0 to 2
Data columns (total 3 columns):

Column Non-Null Count Dtype


0 Id 3 non-null object
1 name 3 non-null object
2 sex 3 non-null object
dtypes: object(3)
memory usage: 200.0+ bytes
None

Released two original articles · won praise 1 · views 18

Guess you like

Origin blog.csdn.net/J2DM9968/article/details/104399215