Get the App
SLTechnology News&Howtos  ›  Servers  › 

How does Pandas convert a list to a data box

Shulou Source: shulou.com Published: 2022-06-01 12:43:29 11月11日 Update

This article mainly explains "Pandas how to convert the list into a data box", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Pandas how to convert the list into a data box"!

There are two ways to convert a list into a data box in Python: the first is that two different lists are converted into a data box, and the second is that a list containing different sublists is converted into a data box.

The first: two different lists are converted into data boxes

From pandas.core.frame import DataFramea= [1Jing 2 Jing 3 Jing 4] # Table ab= [5 Jol 6 Jo 7 Jo 8] # list bc= {"a": a, "b": B} # convert the list A Lingo b to a dictionary data=DataFrame (c) # convert the dictionary to a data frame print (data)

The output is

A b0 1 51 2 62 3 73 4 8

Second: convert a list containing different sublists to a data box

From pandas.core.frame import DataFramea= [[1Jing 2je 3jue 4], [5Jing 6je 7je 8]] # contains two different sublists [1je 2je 3je 4] and [5je 6je 7je 8] data=DataFrame (a) # print (data) written according to the standard of conduct at this time.

Output result:

0 1 2 30 1 2 3 41 5 6 7 8data=data.T# transpose to get the desired result data.rename (columns= {0ghuanaxiajin1 inplace=True) # Note that 0 and 1 are not strings print (data) a b051 2 62 3 73 48 Thank you for reading, this is the content of "how Pandas converts a list into a data box", after the study of this article I believe that you have a deeper understanding of how Pandas converts the list into a data box, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Data different two results learning content dictionary situation output lieutenant general characters strings that is ideas articles more standards knowledge knowledge points articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MariaDB MySQL Shulou Tech Info Apple