In python how to create dataframe with 2 different values from a column
2
0
Entering edit mode
2.5 years ago
jiyecec574 • 0

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

biopandas Python • 887 views
ADD COMMENT
0
Entering edit mode

you are testing for boolean truth value with == and that operation will return True or False

ADD REPLY
2
Entering edit mode
2.5 years ago

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

ADD COMMENT
1
Entering edit mode
2.5 years ago
Mensur Dlakic ★ 27k

Maybe this will work:

new = df [df['atom_name'] ==  'NH1' or df['atom_name'] ==  'NH2']
ADD COMMENT

Login before adding your answer.

Traffic: 3271 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6