0

I have a list of tuples like this

tmp
[('chr19', 50003781, '+', 5303232448),
 ('chr19', 58856544, '+', 5303232448),
 ('chr19', 58856544, '+', 5303232448),
 ('chr10', 52559169, '+', 12460988980),
...]

and I have been following many answers from StackOverflow to convert this into a pandas data frame. Basically I need this

col1    col2      col3     col4
chr19   50003781.  +     5303232448

When I tried to do that with for example this

df = pd.DataFrame(tmp, columns=["col1", "col2", "col3","col4])

I got this error

TypeError: object of type 'int' has no len()

Why?

1 Answer 1

2

That means, tmp is not a list of tuples, there is an integer in it.

For example,

tmp = [('chr19', 50003781, '+', 5303232448),
 ('chr19', 58856544, '+', 5303232448),
 ('chr19', 58856544, '+', 5303232448),
 ('chr10', 52559169, '+', 12460988980), 1]

will give the same error. See if

any(isinstance(t, int) for t in tmp)

is True or not. If True it means there is an integer value in tmp. In that case, you probably want to filter it out when passing tmp to the DataFrame constructor.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.