import pandas as pd
pathfile = 'xxx.json'
data = pd.read_json(pathfile)
data The type of <class 'pandas.core.frame.DataFrame'>
Python machine learning ( eighty-three )Pandas Read JSON data
Code :
import pandas as pd
a = [['a','b','c','d'], ['e','f','g','h']]
a_df = pd.DataFrame(a)
print(a_df)
print(type(a_df))
result :
0 1 2 3
0 a b c d
1 e f g h
<class 'pandas.core.frame.DataFrame'>
Code :
# For simple lists , To DataFrame after , Need to transpose , Is a line
b = ['a','b','c','d']
b_df = pd.DataFrame(b)
print(b_df)
print(type(b_df))
b_df_T = b_df.T
print(b_df_T)
print(type(b_df_T))
result :
0
0 a
1 b
2 c
3 d
<class 'pandas.core.frame.DataFrame'>
0 1 2 3
0 a b c d
<class 'pandas.core.frame.DataFrame'>
all_content = pd.DataFrame(all_content)
after , The data is converted into a column , At this time all_content.to_csv()
Will make mistakes . So add one flag
Judgment of signs , When a column is transposed . if len(all_content) == 0:
all_content = row
flag = True
else:
all_content = np.row_stack((all_content, row))
flag = False
all_content = pd.DataFrame(all_content)
if flag:
all_content = all_content.T
all_content.to_csv(out_file, index=False,header=header,encoding='utf-8-sig')
Hello everyone , This is Wang
Install in company Python+sele