I receive information from an application. I have given a very small example as follows.
import pandas as pd
df = [{'etelat':{'name' : 'sajjad1' , 'last_name' : 'esma1' },
'class_id':{'id':101 , 'name_os' : 'win'}},
{'etelat':{'name' : 'sajjad2' , 'last_name' : 'esma2' },
'class_id':{'id':102 , 'name_os' : 'mac'}}]
df
type(df)
# Import pandas library
import pandas as pd
# initialize list of lists
data = [['sajjad1', 'esma1',101,'win'], ['sajjad2', 'esma2',102,'mac'] ]
# Create the pandas DataFrame
df_new = pd.DataFrame(data, columns = ['etelat_name', 'etelat_last_name','class_id_id', 'class_id_name_os'])
# print dataframe.
df
1- In this case, it answers correctly, but if we want the data, which is in the form of text, I will have a problem.
2- If the data is in a folder and the number of text files is 50, if we want to call the desire of the files with a code. How is this code? enter image description here
If you have your list of lists in a file like the following:
example.txt
you can read the file and convert it to a pandas dataframe:
output:
Edit:
you can load it and convert it to utf-8 and then you get a list of dictionaries that you can deal with.
output:
tested file with: