[Python] Convert list to Pandas [Pandas]

I tried to convert the list obtained by Parsing XML to Pandas DataFrame, but an error occurred when the number of elements differs depending on the XML, so I will describe the remedy.

Failure example

#List stores different numbers of data depending on XML
Date = []
SerialNumver = []
TrendDate = []

df = pd.DataFrame({'Date': Date,
                   'SerialNumber': SerialNumber,
                   'TrendDate': TrendDate})

Error code

ValueError: arrays must all be same length

Even if I count the elements of list, the same number comes out, so it was closed in all directions.

Success story

The description of DataFrame has been changed as follows.

#List stores different numbers of data depending on XML
Date = []
SerialNumver = []
TrendDate = []

#Combine list into one
listData = [Date, SerialNumber, TrendDate]

#Convert to DataFrame..T swaps rows and columns
df = pd.DataFrame(listData).T

#Add column name
df.columns = ['Date', 'SerialNumber', 'TrendDate']

I'm not sure what caused it, but now it's error-free.

Recommended Posts

[Python] Convert list to Pandas [Pandas]
Convert list to DataFrame with python
Python> list> Convert double list to single list
Convert 202003 to 2020-03 with pandas
[Python] How to convert a 2D list to a 1D list
python> Convert tuple to list> aList = list (pi_tuple)
Convert strings to character-by-character list format with python
[python] Convert date to string
Convert numpy int64 to python int
[Python] How to use list 1
Convert Scratch project to Python
[Python] Convert Shift_JIS to UTF-8
[Introduction to Python] <list> [edit: 2020/02/22]
Convert python 3.x code to python 2.x
How to convert JSON file to CSV file with Python Pandas
[Python] list
[Python learning part 3] Convert pandas DataFrame, Series, and standard List to each other
Convert markdown to PDF in Python
[Python] How to use Pandas Series
Workflow to convert formula (image) to python
[Introduction to Python] Let's use pandas
[Python] How to use list 3 Added
[Python] Convert natural numbers to ordinal numbers
Convert decimal numbers to n-ary numbers [python]
[Introduction to Python] Let's use pandas
[Introduction to Python] Let's use pandas
Python> tuple> Convert double tuple to single tuple
Convert from Pandas DataFrame to System.Data.DataTable using Python for .NET
[Introduction to Udemy Python3 + Application] 18. List methods
[Python] How to convert db file to csv
Updated to Python 2.7.9
[Python] Summary of how to use pandas
Python basics: list
[Python] Use pandas to extract △△ that maximizes ○○
Convert memo at once with Python 2to3
My pandas (python)
Convert to HSV
Convert Python> two value sequence to dictionary
[Django] Convert QuerySet to dictionary type list
How to convert Python to an exe file
[Python] Convert csv file delimiters to tab delimiters
Convert psd file to png in Python
Convert Excel data to JSON with python
Convert Hiragana to Romaji with Python (Beta)
Convert from katakana to vowel kana [python]
Use pandas to convert grid data to row-holding (?) Data
[Introduction to Udemy Python3 + Application] 17. List operation
Convert FX 1-minute data to 5-minute data with Python
[Python] Pandas to fully understand in 10 minutes
Python amateurs try to summarize the list ①
Python> Comprehension / Comprehension> List comprehension
Convert Python date types to RFC822 format
[Python] Add total rows to Pandas DataFrame
Convert HEIC files to PNG files with Python
Convert Chinese numerals to Arabic numerals with Python
Summary of how to use Python list
Convert from Markdown to HTML in Python
[Introduction to Udemy Python3 + Application] 16. List type
Adding Series to columns in python pandas
python pandas notes
Python list manipulation