Original English: 09-lesson
Export data from Microsoft's SQL database to CSV, Excel, or text files.
# import library Import
pandas as PD
import sys from
sqlalchemy import create_engine, MetaData, Table, select
Print (' Python version ' + sys.version)
print (' Pandas version ' + pd.__version__)
Python version 3.6.1 | Packaged by Conda-forge | (Default, Mar 2017, 21:57:00)
[GCC 4.2.1 compatible Apple LLVM
This article mainly introduces how to use dict and set in Python. It is the basic knowledge of getting started with Python. If you need it, you can refer to the list of arrays similar to PHP in Python, tuple, dict, and set, where list, tuple, and set are similar to PHP index arrays, while dict is similar to PHP associated arrays,
I. Basic data types
Integer: intString: str (note: \ t equals a TAB key)Boolean value: BOOLListing: Listlist with []Ganso: TupleFor Ganso ()Dictionary: Dict
Note: All data types exist in the class column that you want to correspond to, Ganso and list functions, the list can be modified, the meta-ancestor cannot be modified.
Two. Dictionary all data types:
Common operations:
Index, new, delete, key, value, key-value pair, loop, length
Class
Dict, DictionaryDict full Name dictionary, also known as map in other languages, is stored using key-value (Key-value) and has a very fast lookup speed.This Key-value storage method, when put in, must be based on the key to calculate the storage location of value, so that the time can be obtained by key directly to the value d = {‘Michael‘: 95, ‘Bob‘: 75, ‘Tracy‘: 85}>>> d[‘Michael‘]95注意观察括号,与查找方法。语法要看懂,上面这段代码给dic
A dictionary is the only type of mapping in Python. The hash value in the Mapping type Object (key: Key), and the object pointed to (values: value), is a one-to-many relationship, which isThe elements of the dictionary are divided into two parts, namely the key and the value, a key corresponding to a value, the key cannot be duplicated, and the value can be repeated.1. Create a dictionary.(1). The dictionary uses curly braces ({}) to contain elements, and basic creation is a direct assignment, t
Dict is a dictionary, similar to an array, in which an element corresponds to a key value. For example:D={' a ': ' Zimu ', ' 1 ': ' Shuzi '}Print (d[' a '])Returns the value zimu of the A element in dictionary D.
To determine whether a key is in the dictionary, you can use the statement of key in Dict to queryPrint (' A ' in D)The existence returns true and does not exist to return false.
You can also use
Regular Expressions
\s
Spaces (including tab and other whitespace characters)
[]
1 arbitrary characters in this range
\w
1 letters or numbers
^
The beginning of the line
\d
1 digits
$
End of Line
.
1 arbitrary characters
N
n Characters
*
0~ any of the characters
{N,m}
N~m characters
+
1~ any character (minimum of 1)
()
A dictionary is the only type of mapping in the Python language. A hash value (key, key) and a pointing object (value, value) in a mapped type object are a one-to-many relationship that is often considered a mutable hash table. The object of the dictionary is mutable, which is a container type that can store any number of Python objects, which can also include other container types. The data in the dictionary is unordered. The keys and values in the dictionary are separated by ":", the items are
This article mainly introduces the application details of python dict, set, list, And tuple. For more information, see this article, the tuple application and corresponding examples help readers understand its concepts and principles. The details are as follows:
1. Dictionary (dict)
Dict surrounded {}Dict. keys (),
The curly brace {} indicates that this is a dict, which can be used to look up fractions directly from a given name, d={} since Dict is also a collection, the Len () function can calculate the size of any collection using the Get method provided by Dict itself, returning none,print when key does not exist The first feature of D.get ()
Note: When none is returned, the interactive command line of Python does not display the results. To delete a key, use the Pop (key) method, and the corresponding value will also be removed from dict: >>> d.pop (' Bob ') 75>>> d{' Michael ': Up, ' Tracy ': 85} Be sure to note thatThe order in which the dict is stored inside is not related to the order in which the key is placed. Compared with list,
dict ()function: The dict () function is used to create a dictionary. Returns a dictionary.Grammar:Class Dict (**kwarg) class dict (Mapping, **kwarg) class Dict (Iterable, **kwarg)Parameter description:
**kwargs--Keywords
Mapping--the container of the element.
The Python dictionary has three constructors, Dict (), Dict (**args), dict (mapping), and the first and second constructors are better understood and easier to use.The use of the dict (mapping) constructor is more difficult to understand.1 Dict () constructor can return an e
Python programming: getting started with pandas and getting started with pythonpandas
After finding the time to learn pandas, I learned a part of it first, and I will continue to add it later.
Import pandas as pdimport numpy as npimport matplotlib. pyplot as plt # create a sequence for pandas to create the default int
Summarize the various issues that you have recently encountered in using Python to read and write CSV storage databases.
On the code:
Reload (SYS) sys.setdefaultencoding (' utf-8 ') host = ' 127.0.0.1 ' port = 3306db = ' World ' user = ' root ' password = ' 123456 ' con = M Ysqldb.connect (host=host,charset= "UTF8", Port=port,db=db,user=user,passwd=password) Try: df = Pd.read_sql (sql= R ' select * from City ', Con=con) df.to_sql (' Test ', con=con,flavor= ' MySQL ') except Exception as E
This article mainly gives you a detailed explanation of python in pandas. Dataframe exclude specific Line Method sample code, the text gives the detailed sample code, I believe that everyone's understanding and learning has a certain reference value, the need for friends to see together below.
Pandas. Dataframe Exclude specific lines
If we want a filter like Excel, as long as one or more of the rows, you c
Querying and analyzing data is an important function of pandas, is also the basis of our learning pandas, the following article mainly introduces you about how to use the data analysis of Python pandas query data, the text through the sample code introduced in very detailed, the needs of friends can reference , let's take a look below.
Objective
In the field of
the same way. Download scipy on the link below.http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipyOur Python is 2.7,windows 32-bit, so choose SCIPY-0.18.1-CP27-CP27M-WIN32.WHL Download.Run "Pip Install SCIPY-0.18.1-CP27-CP27M-WIN32.WHL"So NumPy and scipy two good base friends will be done.Step 4. Installing Matplotlib,pandas and Scikit-learnThere's nothing to say, just run the following command at the command line. Note that installing matplotlib before
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.