this: pd.concat(vals, axis=1).transpose() yields: AT->GC GC->AT Ara-4/m4 1988 1831…
- User
this:
pd.concat(vals, axis=1).transpose()
yields:
AT->GC GC->AT Ara-4/m4 1988 1831 Ara-3/m3 947 1468 Ara-1/m1 3427 390 Ara-2/m2 1342 1341 Ara+3/p3 2396 2453 Ara+6/p6 7571 829
how can I get each number but as the proportion of the row?
I was thinking something like:
pd.concat(vals, axis=1).transpose().map(lambda row[0], row[1], ...
- Assistant
You're on the right track with using a lambda function to transform each row into the proportion of the row. However, you need to apply this function correctly to each row of the dataframe. You can use the
.apply()method withaxis=1to specify that the function should be applied to each row.Here's what your code could look like:
import pandas as pd # Assuming 'pd.concat(vals, axis=1).transpose()' gives you the following DataFrame: df = pd.concat(vals, axis=1).transpose() # Now apply a lambda function to each row to get the proportions df_proportions = df.apply(lambda row: row / row.sum(), axis=1)This lambda function takes each row, and divides every element in the row by the sum of the row, effectively converting all the values to their respective proportions of the total count per row.
Now
df_proportionsshould contain the same index and columns asdfbut with each number converted to its proportion of the row total.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.