In R, when adding new data of unequal length to a data frame, the values repeat to fill the data frame:
df <- data.frame(first=c(1,2,3,4,5,6)) df$second <- c(1,2,3)
first second 1 1 1 2 2 2 3 3 3 4 4 1 5 5 2 6 6 3
However, pandas requires equal index lengths.
How do I "fill in" repeating data in pandas like I can in R?
Seems there is no elegant way. This is the workaround I just figured out. Basically create a repeating list just bigger than original dataframe, and then left join them.
import pandas df = pandas.DataFrame(range(100), columns=['first']) repeat_arr = [1, 2, 3] df = df.join(pandas.DataFrame(repeat_arr * (len(df)/len(repeat_arr)+1), columns=['second']))
- How can I print literal curly-brace characters in python string and also use .format on it?
- How to access index in function for applymap in pandas?
- Finding all possible permutations of a given string in python
- Using regex to alter digits pandas
- regaining original line breaks pandas \n
- Error when using two matching foreignKeys in django
- Proper use of method overriding with multiple inheritance?
- Python dynamically define function within function
- Lazy logger message string evaluation
- Include_exe | Install `python.exe` and related files | 1
- Add –cleanup option to python3 -m test to remove `test_pyt
- thon 2.7 at https://docs.python.org. If you want to understa
- GI scripts * mod_python * FastCGI and SCGI
- utils SIG at https://www.python.org/community/sigs/current/d
- sourceforge.net/projects/python/. The most important of the
- w recognises the word “python” as an instruction to star
- !/usr/local/bin/python as the very first line
- d. > > —https://mail.python.org/pipermail/python-3000/20
- here in the world is www.python.org located? * Why is