繁体   English   中英

将多值字典转换为 python 中的 Dataframe

[英]Convert a multi value dictionary to a Dataframe in python

词典

{'password': ['Input data fields to enter - 1) Username 2) Password 3) Re-enter Password 4) Security question 5) Security answer\nUsername data field specifications - At least one uppercase, \nUsername data field specifications - At least one lowercase.',

  'Password data field specifications - At least 7 characters, \nPassword data field specifications - 1 number, \nPassword data field specifications - 1 uppercase letter, \nPassword data field specifications - 1 lowercase letter, \nPassword data field specifications - one special charactersss.',
  'Password criteria should be displayed to the user when user clicks inside the password data field.',
  "Green check mark next to 'Password' data field should be displayed that indicates to the user after typing password that the entry meets criteria.",
  "Red cross mark next to 'Password' data field should be displayed that indicates to the user after typing password that the entry does not meet criteria.",
  "Validate that inputs in 'Password' and 'Re-enter Password' data fields match- Green check mark next to 'Re-enter' password data field should be displayed that indicates to the user after typing if passwords match\n'Password' and 'Re-enter Password' entries should be masked.",
  'Password entries will show the keystroke typed, and then after two seconds the entered character is masked.',
  'If \'Password\' entry does not match criteria specified and user hits Submit, show error alert "Password entry does not meet criteria".',
  "If entries in 'Password' and 'Re-enter Password' do not match and user hits Submit, show error alert 'Password entries do not match'."]}

通过将这些值列表转换为具有相同键的 DF 需要数据帧

我不确定您想要的输出,可能是您想要这样的东西。

import pandas as pd

df = pd.DataFrame({'password': ['Input data fields to enter - 1) Username 2) Password 3) Re-enter Password 4) Security question 5) Security answer\nUsername data field specifications - At least one uppercase, \nUsername data field specifications - At least one lowercase.',

  'Password data field specifications - At least 7 characters, \nPassword data field specifications - 1 number, \nPassword data field specifications - 1 uppercase letter, \nPassword data field specifications - 1 lowercase letter, \nPassword data field specifications - one special charactersss.',
  'Password criteria should be displayed to the user when user clicks inside the password data field.',
  "Green check mark next to 'Password' data field should be displayed that indicates to the user after typing password that the entry meets criteria.",
  "Red cross mark next to 'Password' data field should be displayed that indicates to the user after typing password that the entry does not meet criteria.",
  "Validate that inputs in 'Password' and 'Re-enter Password' data fields match- Green check mark next to 'Re-enter' password data field should be displayed that indicates to the user after typing if passwords match\n'Password' and 'Re-enter Password' entries should be masked.",
  'Password entries will show the keystroke typed, and then after two seconds the entered character is masked.',
  'If \'Password\' entry does not match criteria specified and user hits Submit, show error alert "Password entry does not meet criteria".',
  "If entries in 'Password' and 'Re-enter Password' do not match and user hits Submit, show error alert 'Password entries do not match'."]})

print df

Output:

    password
0   Input data fields to enter - 1) Username 2) Pa...
1   Password data field specifications - At least ...
2   Password criteria should be displayed to the u...
3   Green check mark next to 'Password' data field...
4   Red cross mark next to 'Password' data field s...
5   Validate that inputs in 'Password' and 'Re-ent...
6   Password entries will show the keystroke typed...
7   If 'Password' entry does not match criteria sp...
8   If entries in 'Password' and 'Re-enter Passwor

我不太确定你想要什么,但是

import pandas as pd
dataframe = pd.DataFrame('Your dictionary comes here')

另外:如果您只有一个数组,并且需要将其放入 dataframe

import pandas as pd
dataframe = pd.DataFrame() # Without any arguments
dataframe['The Coulmn name'] = 'Your array comes here'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM