in Education by
I have the string looks like this """PID TTY TIME CMD 1 ? 00:00:01 systemd 2 ? 00:00:00 kthreadd 3 ? 00:00:00 rcu_gp 4 ? 00:00:00 rcu_par_gp""" When I try to access the data["PID"] it will give me 1,2,3,4 and so for the other headers. To overcome that I am trying to using pandas and StringIO to convert it to a dataframe. But it will be better if the logic is python related and not with pandas Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
You can use the below approach: from io import StringIO text = StringIO("""PID TTY TIME CMD 1 ? 00:00:01 systemd 2 ? 00:00:00 kthreadd 3 ? 00:00:00 rcu_gp 4 ? 00:00:00 rcu_par_gp""") Output: print(pd.read_csv(text, sep="\s{2,}")) PID TTY TIME CMD 0 1 ? 00:00:01 systemd 1 2 ? 00:00:00 kthreadd 2 3 ? 00:00:00 rcu_gp 3 4 ? 00:00:00 rcu_par_gp Do check out Data Science with Python course which helps you understand from scratch.

Related questions

0 votes
    Is there any way to split the string if it contains an uppercase letter but not the first letter? For example, ... solution to it? Select the correct answer from above options...
asked Jan 8, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me why Python is better than R for Data Science? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me why Python is used in Data Science? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me whether Python is necessary for Data Science? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me whether Python is good for Data Science? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me whether Python is enough for Data Science? Select the correct answer from above options...
asked Jan 18, 2022 in Education by JackTerrance
0 votes
    Do the Data Science course requires Python learning in-depth? Select the correct answer from above options...
asked Jan 18, 2022 in Education by JackTerrance
0 votes
    Do I need coding skills for Data Science using Python? Select the correct answer from above options...
asked Jan 17, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me what should I learn in Python for Data Science? Select the correct answer from above options...
asked Jan 17, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me where can I learn Python for Data Science? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me how do I start learning Python for Data Science? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me what is Python with Data Science? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me whether Python is sufficient for Data Science? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me how Python is better for Data Science compared to R? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me what are the best Python IDEs for Data Science? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
...