字符串列表。
我想将它们排列成以下格式。每三行一组,从左到右,从上到下:
通过重塑,我只能做到以下几点:
import pandas as pd
import numpy as np
data = [
"by Emily Dickinson",
"There is another sky,",
"Ever serene and fair,",
"And there is another sunshine,",
"Though it be darkness there;",
"Never mind faded forests, Austin,",
"Never mind silent fields -",
"Here is a little forest,",
"Whose leaf is ever green;",
"Here is a brighter garden,",
"Where not a frost has been;",
"In its unfading flowers",
"I hear the bright bee hum:",
"Prithee, my brother,",
"Into my garden come!"]
df = pd.DataFrame(data)
df_1 = pd.DataFrame(np.reshape(df.values,(5,3)))
如何解决?谢谢。
P.s。 “ Row#”和“ String”仅用于清晰阅读。我只想实现内容的重新排列。
只需更改重塑参数和通过顺序参数
df_1 = pd.DataFrame(np.reshape(df.values,(3,5),order='F'))