我如何借助两个列表和一个循环下的变量创建数据框
我有一个名为 Strike 的变量,在 Strike 中,变量值会定期更改,因为它处于循环状态。
for i in range(len(df.strike)):
Strike = df.strike.iloc[i]
list1 = ['0-50', '50-100', '100-150'.......]
list2 = [2000, 132.4, 1467.40, ..........]
df = [] # Here i have to create dataframe
Strike 包含类似 - 33000, 33100, 33200, 33300.......
的值,因此它至少包含 145 个值。 我想排成行。
我有两个列表,它们也会不时更改,因为它也在循环中。
list1 = ['0-50', '50-100', '100-150'.......]
list1 我想制作列。
并且 list2 包含数值 -
list2 = [2000, 132.4, 1467.40, ..........]
我需要这种格式的数据框。 列表 1 应该是列名称,列表 2 应该是值,并且罢工变量应该是行。 但我不明白如何创建这个数据框。
I have a variable whose name is Strike, in Strike variable values regularly change because it is under a loop.
This is my Dataframe
code example -
for i in range(len(df.strike)):
Strike = df.strike.iloc[i]
list1 = ['0-50', '50-100', '100-150'.......]
list2 = [2000, 132.4, 1467.40, ..........]
df = [] # Here i have to create dataframe
Strike contains values like - 33000, 33100, 33200, 33300.......
so on it contains at least 145 values.
which I want to make rows.
And I have two list which is also changing from time to time because it is also under a loop.
list1 = ['0-50', '50-100', '100-150'.......]
list1 I want to make columns.
and list2 contains numeric values -
list2 = [2000, 132.4, 1467.40, ..........]
I need dataframe in this format.
List 1 should we column name, and list 2 should we values and strike variable should be rows.
but I don't understand how can I create this data frame.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IIUC您可以使用
DataFrame
直接使用reshape
d numpy 数组作为输入:输出:
IIUC you could use the
DataFrame
constructor directly with areshape
d numpy array as input:output: