字符串列表
我想把它们排列成下面的格式。每3行一组,从左到右,从上到下:
通过重塑,我只能做到以下几点:
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)))
怎么解决?谢谢你
请注意,“行#”和“字符串”仅用于清晰阅读。我只想实现内容的重新排列
只需更改重塑参数和传递顺序参数
相关问题 更多 >
编程相关推荐