Write the story behind the series

I’ve written the basics of the interview series. What’s next

Pandas!

Developed by foreigners, it is translated into Chinese as panda

Cool, cool, down to earth a numpy-based library

Stem what? It’s for data analysis

Data analysis is the next very large branch of the Python architecture

So good, a lot of people will see it (bloggers are not)

Or you might lose interest in her

After all, the blogger is called dream Eraser

Erasing your programming dreams is part of my effort

Download as per this library

For this library, install Easy

You just do this, this, and then in the middle of this, there is a problem, baidu, this, this, that… .

Hey hey

I actually used python3.6 and installed it using the following command

pip install pandas 
Copy the code

Domestic, general installation is relatively slow, you add a Tsinghua university source is good

pip install pandas -i  https://pypi.tuna.tsinghua.edu.cn/simple/
Copy the code

The download and install speed is low

Pandas version for

Pandas 0.23.3

Your version is higher than I should be,

After all, I’m an old programmer

Pandas website pandas.pydata.org/ without translation of pseudo Chinese website www.pypandas.cn/index.html

After installation

After some simple operations, if you don’t have any bugs during the process congratulations, the installation is successful

Now open any of your development tools

I usually use pyCharm, the “free version”

Create a file and type the following code to run directly

import pandas
Copy the code

No error, perfect, one library learned

And, of course, it’s usually written as

import pandas as pd
Copy the code

You are in line with international programmers

2. What do pandas do

If your English is good, go directly to the official documents

Just look at it

If English is not good, it doesn’t matter

Pandas is like using code to manipulate Excel

In PANDAS, you will learn a new data structure

Series

What a great annotation, combining Chinese and English.

Before explaining this problem, let’s create one and look at it in code

It makes sense

Write the following code

import pandas as pd

my_series = pd.Series(['我'.'is'.'dream'.'Eraser'])
print(my_series)
Copy the code

The results

012dream3Eraser dType: objectCopy the code

Did you see anything?

Don’t worry, get it into Excel and copy it

series

In Excel, you need to make sure you know what a row is, what a column is, okay

After you create a series from the list, each row starts with a serial number starting at 0

This new sequence, remember, is called an index, and since it’s called an index, we can set the index

If you have any programming experience, you know that the corresponding index value is called index in English

Every programming language index is basically set to index

So let’s rewrite it

import pandas as pd

my_series = pd.Series(['我'.'is'.'dream'.'Eraser'],index=['a'.'b'.'c'.'d'])
print(my_series)
Copy the code

Let’s see what happens to the index

A I B is C dream D eraserCopy the code

Keep digging in and make sure the index is the same length as the previous list

What do you mean?

Pd. Series ([‘ me ‘, ‘is’,’ dream ‘, ‘the eraser’], index = [‘ a ‘, ‘b’, ‘c’, ‘d’, ‘e’]) error pd. The Series ([‘ me ‘, ‘is’,’ dream ‘, ‘the eraser’], index = [‘ a ‘, ‘b’, ‘c’]) error

A function that declares a series can also take a name argument

Please see the

import pandas as pd

my_series = pd.Series(['我'.'is'.'dream'.'Eraser'],index=['a'.'b'.'c'.'d'],name='Dream sequence')
print(my_series)
Copy the code

The results of Chou Chou

A I B is C dream D eraserCopy the code

Next, you can complete the previous list parameters as well

import pandas as pd

my_series = pd.Series(data = ['我'.'is'.'dream'.'Eraser'],index=['a'.'b'.'c'.'d'],name='Dream sequence')
print(my_series)

Copy the code

To summarize

Creating a series is very easy, just adopt

Pd. Series(data= list,index= list,name= name)Copy the code

Other Creation methods

You can also use a dictionary

my_series1 = pd.Series({'a':'Non-undergraduate Programmer'.'b':'the male number'})
print(my_series1)
Copy the code

It is also possible to store different types in a Series

my_series2 = pd.Series([1.1.2.True.'MyName'])
print(my_series2)
Copy the code

For this Series, you can just think of it as excel with one column

Yi? Someone asked me, I just printed 2 columns

It doesn’t matter, that’s an index, just a sequence number to get the value

Don’t believe me, let’s get it

my_series2 = pd.Series([1.1.2.True.'MyName'])
print(my_series2[0])
Copy the code

I think I printed it

In try

import pandas as pd

my_series = pd.Series(data = ['我'.'is'.'dream'.'Eraser'],index=['a'.'b'.'c'.'d'],name='Dream sequence')
my_series1 = pd.Series({'a':'Non-undergraduate Programmer'.'b':'the male number'})
my_series2 = pd.Series([1.1.2.True.'MyName'])
print(my_series1['a'])  Access to "non-undergraduate programmers" via index A
print(my_series[0])  My_series ['a'] = my_series['a'

Copy the code

In this way, does a series look a bit like a list in Python?

It’s like a dictionary

That’s right. See you in the next post

We will continue to work on series

Finally, welcome to the public name of a nagging programming engineer, not an undergraduate programmer

If you don’t want to search, just open this link

dwz.cn/r4lCXEuL

Or pull out your phone and shoot this