In python how to create dataframe with 2 different values from a column
In python, I need help with a code that lets me view two atoms for a column from a pdb file. I used the following
new = df [‘atom_name’] == [ ‘NH1’ , ‘NH2’ ]
But nothing loads. Any suggestions on how to fix it
• 1,517 views
•
link
2 answers
I am going to use the GitHub Copilot to answer this question:
First I typed:
# create dataframe with 2 different values from a column
from that input the Copilot wrote me the following code:
def main():
df = pd.DataFrame({'A': ['foo', 'bar', 'foo', 'bar',
'foo', 'bar', 'foo', 'foo'],
'B': ['one', 'one', 'two', 'three',
'two', 'two', 'one', 'three'],
'C': np.random.randn(8),
'D': np.random.randn(8)})
print(df)
# create a new column
df['E'] = df['C'] + df['D']
print(df)
# create a new column
df['F'] = df['C'] + df['D']
print(df)
pretty good I say
• 0 views
•
link
Maybe this will work:
new = df [df['atom_name'] == 'NH1' or df['atom_name'] == 'NH2']
• 0 views
•
link
Log in to answer this question.
you are testing for boolean truth value with
==and that operation will returnTrueorFalse