Discover python convert dataframe to list, include the articles, news, trends, analysis and practical advice about python convert dataframe to list on alibabacloud.com
]). [ 1,2,3,4,5,6]1.4 Python can use *n to generate more than one new sequence, and in the new sequence, the original sequence is repeated n times>>> [1]*4[1, 1, 1, 1]An empty list can be expressed using [],None is a built-in value for Python, representing null values, meaning that no elements are placed inside, and if you want to initialize a 10-length
(list): Returns the maximum value of the element3, Min (list): Returns the minimum value of the list element4. List (seq): Convert tuples to lists5, Enumerate usage (print the corresponding subscript of the element)While removing the label, the elementLengthPrint (len (name
of the list with the parameter, and throws an exception if the element of the specified content does not existPrint ListThe code above demonstrates how to use the Append, insert, pop,remove of the list to insert and delete list elements, and shows how to iterate through the list elements with a for loop. Four.In addit
Python list array usage instance parsing, pythonarray
This article describes in detail how to use the Python list array as an example. Share it with you for your reference. The details are as follows:
The list in Python is similar
1
CMP (List1, List2)Compare two elements of a list
2
Len (list)Number of list elements
3
Max (list)Returns the maximum value of a list element
4
MIN (list
List is the most common Python data typeCreate a list
Create a list
>>> l = [1, 2, 3, 4, 5 ]>>> l[1, 2, 3, 4, 5]
Create an empty list (Method 1)
>>> l = []>>> l[]
Create an empty list (Method 2
list, each character in the string becomes an element in the list.The list-to-string cannot go directly, because if the direct transfer takes the "[]" marker of the list as part of the string. List-to-string, we can only write a function to convert:1 li=[123,'sre', 567,true
; la.extend(lb)>>> la[1, 2, 3, 'qiwsir', 'python']>>> lb['qiwsir', 'python']
The example above shows how to append the lb to the end of the two lists, one is la and the other is lb, that is, to add all the elements in the lb to la, expand la.
I must be curious when learning a program. in an interactive environment, I often experiment with my own ideas. sometimes I am stupid.
>>> la = [1,2,3]>>> b = "abc">
append the lb to the end of the two lists, one is la and the other is lb, that is, to add all the elements in the lb to la, expand la.
I must be curious when learning a program. In an interactive environment, I often experiment with my own ideas. Sometimes I am stupid.
>>> la = [1,2,3]>>> b = "abc">>> la.extend(b)>>> la[1, 2, 3, 'a', 'b', 'c']>>> c = 5>>> la.extend(c)Traceback (most recent call last): File "
In the above experiment, What do you learn about the official website? Originally, if e
iterable]. '''return [x for x in range (1, 10)] def str_to_list (s): ''' Using a string to convert list ''' if s! = None: return list (s) else: return [] def main (): test_listA = create_empty_list () print (test_listA) print ('#' * 50) test_listB = create_common_list () print (test_listB) print ('#' * 50) test_listC = create_common_list2 () print (test_listC) p
Recently prepared to learn Python system, in order to be able to find in time, first recorded.First of all, what is called sequence, before in use, feel the concept of a vague, today deliberately read the next, the sequence is the most basic data structure in Python, each element of the sequence is assigned an ordinal, that is, the position of the element, also become an index. Similar to "array".
follows:
Copy the Code code as follows:
L = [' spam ', ' spam ', ' spam! ']
Operation:
Python Expressions
Results
Description
L[2]
' spam! '
Read the third element in the list
L[-2]
' Spam '
Reads the second-to-last element in a list
L[1:]
[' Spam ', ' spam! ']
To intercept a
another lb, to append lb to the back of LA, that is, to add all the elements of lb to LA, that is, let la expand.
Learning procedures must be curious, I in the interactive environment, often experimenting with their own ideas, sometimes more foolish ideas.
>>> La = [1,2,3]>>> B = "abc" >>> La.extend (b) >>> la[1, 2, 3, ' A ', ' B ', ' C ']>>> ; c = 5>>> La.extend (c) Traceback (most recent call last): File "
", line 1, in
TypeError: ' int ' object
is not itera
, everyone. That is a great magic show!")1.2Create a list of values1. Use function range ()The Python function range () allows you to easily generate a series of numbers. for in range (1,5): print(value)Range () just prints the digital 1~4, which is the result of the bad behavior you see frequently in programming languages. The function range () lets Python
]
Combination
[' hi! '] * 4
[' hi! ', ' hi! ', ' hi! ', ' hi! ']
Repeat
3 in [1, 2, 3]
True
Whether the element exists in the list
For x in [1, 2, 3]: print x,
1 2 3
Iteration
Python list interception
Python Expre
Python list has a lot of knowledge to learn. Next let's take a look at the relevant code. Only continuous learning can we better write the relevant code. The Python list (list) is similar to the variable array ArrayList in C # and is used for sequential storage structure.
Th
Code is as follows:>>> 1, 2, 3(1, 2, 3)>>> ()()>>> 4242>>> 42,(42 ,)>>> (42 ,)(42 ,)
Tuples are also enclosed by parentheses (most of the time). Empty tuples can be expressed by two parentheses that do not contain content:
Tuple Function
The functions of the tuple function are basically the same as those of the list function: Use a sequence as a parameter and convert it to a tuples.
Copy codeThe Code is as
GansoPython has built-in data types that have sequence lists that cannot be modified once initialized . The tuple is immutable, so the code is more secure. Can contain different data types: integer, floating-point, String, list, tuple, dict, set, bool, NULL, constantEmpty Ganso: tuple1= (); Tuple2=tuple ()function: Len (), del delete entire tuple, tuple () convert list
Php Chinese network (www.php.cn) provides the most comprehensive basic tutorial on programming technology, introducing HTML, CSS, Javascript, Python, Java, Ruby, C, PHP, basic knowledge of MySQL and other programming languages. At the same time, this site also provides a large number of online instances, through which you can better learn programming... Python learning
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.